[XSLT] determining what node() finds?

Mike Kamermans

Usenet Archive
Joined
Aug 10, 2004
Messages
14
Reaction score
0
Is there a way to determine what a node find returns? For instance, if I have a snip of XSLT that looks like:

<xsl:for-each select="node">
...
</xsl:for-each>

Is there a way to, for each node found, generate what kind of node it found, like <some_element> or <#PCDATA> or something that indicates the type of element it found?

(sort of like an <xsl:value-of select="node-type"/>, except that doesn't exist of course)

- Mike Kamermans
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
Mike Kamermans said:
Is there a way to, for each node found, generate what kind of node it found, like <some_element> or <#PCDATA> or something that indicates the type of element it found?

You could match it against some templates to find the type, and store the result in a variable:

<xsl:template match="foo">
<xsl:for-each select="node">
<xsl:variable name="type">
<xsl:apply-templates mode="type" select="."/>
</xsl:variable>
type is: <xsl:value-of select="$type"/>
</xsl:for-each>
</xsl:template>

<xsl:template match="*" mode="type">
<xsl:text>element</xsl:text>
</xsl:template>

<xsl:template match="text" mode="type">
<xsl:text>text</xsl:text>
</xsl:template>

<xsl:template match="comment" mode="type">
<xsl:text>comment</xsl:text>
</xsl:template>

<xsl:template match="processing-instruction" mode="type"> <xsl:text>pi</xsl:text> </xsl:template>

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top