How do XSLT get the attributes inside the name, my item tag, only if it’s true?

Asked

Viewed 379 times

0

<bloco>

   <item nome="imagem">true</item>
    <item nome="imagem">false</item>

</bloco>

1 answer

1

Use a template to select all elements item, test content value (using . or node() or text()) and print the attribute value nome if the content is equal to the string 'true'.

Here’s an example of a stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    version="1.0">

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

    <xsl:template match="item">
        <xsl:if test=". = 'true'">
            <xsl:value-of select="@nome" />
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.