0

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.

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.