Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to test match in an xsl:apply-template?

Tags:

xslt

In my second xsl:template match, how do I test for the match pattern? For example if the match patter is title, I want to output different value?

  <xsl:template match="secondary-content">
    <div class="secondary">
      <xsl:apply-templates select="title" />
      <xsl:apply-templates select="block/content | content" />
    </div>
  </xsl:template>
  <xsl:template match="title|content|block/content">
    <xsl:copy-of select="node()" />
  </xsl:template>
like image 866
steve Avatar asked Aug 22 '11 18:08

steve


Video Answer


1 Answers

Good question, +1.

In the second template, use this test expression:

test="self::title"

or

test="local-name() = 'title'"

For example, you can use

<xsl:choose>
  <xsl:when test="self::title">
    <someThing>foo</someThing>
  </xsl:when>
  <xsl:otherwise>
    <xsl:copy-of select="node()" />
  </xsl:otherwise>
</xsl:choose>
like image 175
LarsH Avatar answered Oct 19 '22 19:10

LarsH