Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fun with XSL: multiple templates and uses of child nodes

Status
Not open for further replies.

TeaAddictedGeek

Programmer
Apr 23, 1999
271
US
I have two places where the same data is displayed but there are different rules for each place as to how they are displayed.

Place #1 has a template, matching on the node name, and is the main display for the data on the page.

Place #2 takes the same data, but only *part* of it and its child nodes, and leaves out the rest of the child nodes.

Let me try to illustrate this as an example.

<mainnode>
<parentnode1>
Lots of text <child_node1>with flashing colors</child_node1>!
<child_node2>really really long paragraph that goes on forever and a day</child_node2>
</parentnode1>
<parentnode2>
etc...
</parentnode2>
</mainnode>

One section will display everything in parentnode1, and another section will only display the text plus child_node1, but not child_node2. I have a template match to do the entire display (it's recursive and multiple nodes of the same name can be under child nodes) and am trying to figure out how to do the section that only displays the text plus child_node1. Is this possible?

Yes, I am doing lots of crazy things with XML and XSL. Maybe when I'm done, I should write my own XML help site. :p

"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs."
-Joseph Weizenbaum
 
Check out the uses of "mode" attribute of template and apply-template elements.
 
Ok, that could help me part way. Thanks! But I still don't know how I would prevent from displaying the second child node.

"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs."
-Joseph Weizenbaum
 
Here's what I have so far, but it only outputs the text, and completely ignores ALL of the rest of the nodes, and I need child_node1:

<xsl:apply-templates select="parentnode1" mode="chk_value" />

..

<xsl:template match="parentnode1" mode="chk_value">
<xsl:apply-templates mode="chk_value"/>
</xsl:template>

<xsl:template match="text()" mode="chk_value">
<xsl:value-of select="." />
</xsl:template>

<xsl:template match="child_node2" mode="chk_value" />

<xsl:template match="child_node3" mode="chk_value" />

Help?


Thanks,
Andrea

Started By kyrene on Jan 13, 2006 at 7:25:24 AM
This message has been edited.
Edit this message

"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs."
-Joseph Weizenbaum
 
Wait, left out part of it:

<xsl:template match="child_node1" mode="chk_value">
<xsl:choose>
<xsl:when test="@role='bold'">
<b><xsl:value-of select="." /></b>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="." />
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs."
-Joseph Weizenbaum
 
Never mind, I solved the problem: for whatever reason, it didn't like the bold tags. I removed them and the code works.

"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs."
-Joseph Weizenbaum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top