Pregunta

I need to extract some values from the following xml file.

<PAIR symbol="sym1">
        <value-date row="0" name="TOM" date="2014-05-15"/>
        <value-date row="0" name="SP" date="2014-05-16"/>
<PAIR>

I have to print like this: sym1 2014-05-15 sym1 2014-05-16

I used the following cmnd in linux to do this: xsltproc a.xslt xmlfilename

My a.xslt is:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//PAIR">
"<xsl:value-of select="@symbol"/>"
</xsl:template>
<xsl:template match="value-date">
"<xsl:value-of select="@date"/>"
</xsl:template>
</xsl:stylesheet>

But it is extracting the symbol only. Not extracting the date.

¿Fue útil?

Solución

set your a.xslt like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:strip-space elements="*"/>

    <xsl:output indent="yes"/>

    <xsl:template match="/">
        <xsl:for-each select="PAIR/value-date">
            <xsl:value-of select="../@symbol"/>
            <xsl:text> </xsl:text>
            <xsl:value-of select="@date"/>
            <xsl:text>&#xA;</xsl:text>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top