1

I have a very simple file from which I would like to extract the number values, only when the type is flower.

<myRoot>
    <header>
        ...
    </header>
    <body>
        ...
        <div type="animal" number="431">text1</div>
        <div type="flower" number="812">text2</div>
        <div type="flower" number="619">text3</div>
        ...
    </body>
</myRoot>

The exit I'm waiting for is :

812
619

My current xslt file is :

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="no" />
    <xsl:template match="//div">
        <xsl:value-of select="@type='flower'"/>
    </xsl:template>
    <xsl:template match="text()" />
</xsl:stylesheet>
1
  • 1
    If you use xsl:output method="html", I would expect to see some HTML in the result you want, yet you have only shown plain text. As for selecting your attributes, use //div[@type = 'flower']/@number as the path, with an XSLT 2 or 3 processor you can simply use that path in <xsl:value-of select="//div[@type = 'flower']/@number"/>, with an XSLT 1 processor you will need to push the selected attributes through a template or pull them in through xsl:for-each. Commented Nov 27, 2018 at 16:11

1 Answer 1

2

Try

<xsl:template match="div[@type='flower']">
   <xsl:value-of select="@number"/>
</xsl:template>
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.