XSLT/XPATH - Expression

Card Puncher Data Processing

About

XSLT uses the expression language defined by XPath.

Expressions are used in XSLT for a variety of purposes including:

  • selecting nodes for processing;
  • specifying conditions for different ways of processing a node;
  • generating text to be inserted in the result tree.

Example

If test expression

<xsl:template match="myTemplateName">

  <xsl:if test="@name='nico'">
    <xsl:text>
    The attribute name has the value nico
    </xsl:text>
  </xsl:if>

  <xsl:if test="@name">
    <xsl:text>
    The current node has an name attribute.
    </xsl:text>
  </xsl:if>

  <xsl:if test="childNodeAge">
    <xsl:text>
    The current node has at least one child element named "childNodeAge"
    </xsl:text>
  </xsl:if>
  
  <xsl:if test="not(childNodeAge)">
    <xsl:text>
       The current node doesn't have a child element named "childNodeAge"
    </xsl:text>
  </xsl:if>

  <xsl:if test="count(nodeChildren) > 3">
    <xsl:text>
    The current node has more than 3 child elements named "nodeChildren".
    The logical operator != and < can also be used
    </xsl:text>
  </xsl:if>

  <xsl:if test="(@name = 'nico') or (@yearBirth='1973')">
    <xsl:text>
    The current node has an attribute name with the value 'nico' or
    an other yearBirth attribute with the value '1973'. The operator and can also be used
    </xsl:text>
  </xsl:if>
  
  <xsl:if test="position()=last()">
        <xsl:text>The xpath functions can also be used</xsl:text>
  </xsl:if>

  <xsl:if test="text()=''">
        <xsl:text>The current node contains not text. . is an alias for text(), so you can use [.=""]</xsl:text>
  </xsl:if>
  <xsl:if test="nodeBelow/text()!=''">
        <xsl:text>The node below (namde nodeBelow) contains text.</xsl:text>
  </xsl:if> 
 
</xsl:template>

Documentation / Reference





Discover More
Card Puncher Data Processing
XSLT - Flow Control

where: the test is an expression Single quotes are required around the attribute values. Otherwise, the XSLT processor attempts to interpret the word ordered as an XPath function instead of as a string....



Share this page:
Follow us:
Task Runner