Previous | Next | Indexes
Zvon > Tutorials > XSLT 2.0 Tutorial > Use When (1/2) >

Use-when attribute

Attribute use-when can be used on any element in the stylesheet. If the boolean value of the expression in this attribute equals "false" then the element and its descendants are removed from the stylesheet.

It is important not to forget to put this attribute into xsl namespace when it is used on elements from other namespaces.

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/aaa">
                  <xxx>
                        <xsl:value-of  use-when="true()"
                                    select="111"/>
                  </xxx>
                  <yyy>
                        <xsl:value-of  use-when="false()"
                                    select="333"/>
                  </yyy>
                  <zzz  xsl:use-when="false()"/>
                  <ooo  use-when="false"/>
                  <ppp  xsl:use-when="true()"
                              use-when="false"/>
                  <qqq  xsl:use-when="false()"
                              use-when="true"/>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa/>
Output

      <xxx>111</xxx>
      <yyy/>
      <ooo  use-when="false"/>
      <ppp  use-when="false"/>


Previous chapter: Errors
Next chapter: Collations
Previous page: - - -
Next page: Use-when for compatibility