Pablo
Pablo

Reputation: 10602

XSLT Select Just Specific Childs

How can I get, in xslt, all childs that have another child with some specific name?

For example:

<node>
    <text>
       <char></char>
    </text>
    <text>
       <char></char>
    </text>
    <text>
        <tag></tag>
    </text>
</node>

I want to call to an apply template to all text nodes that has a tag inside, and call another template for all text node, that has a char inside

Upvotes: 0

Views: 44

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167506

<xsl:template match="node">
  <xsl:apply-templates select="text[tag]"/>
  <xsl:call-template name="foo">
    <xsl:with-param name="elements" select="text[char]"/>
  </xsl:call-template>
</xsl:template>

should give you an idea although I would suggest to use apply-templates in both cases, with different modes or suitable match patterns:

<xsl:template match="node">
  <xsl:apply-templates/>
</xsl:apply-templates>

<xsl:template match="text[tag]">
  ...
</xsl:templates>

<xsl:template match="text[char]">
  ...
</xsl:templates>

Upvotes: 1

Related Questions