|
Subject: Re: [xsl] Grouping multiple tags into one parent tag From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sun, 15 Feb 2009 13:23:06 -0500 |
Thank you all for your responses. Ken this is exactly what I was trying to do! The only thing is, I am also using:
<xsl:output method="xml" cdata-section-elements="field"/>
To wrap the contents of the field element in a cdata tag. After using the template rule that you provided, that cdata-section-element no longer works. I'm not sure why.
<field name="body"> <![CDATA[ <p>content here</p> <p>content here</p> <p>content here</p> ]]> </field>
<xsl:output method="xml" cdata-section-elements="field"/>
<xsl:template match="body">
<xsl:if test="not(preceding-sibling::body)">
<field name="body">
<xsl:for-each select="../body">
<xsl:text><p></xsl:text>
<xsl:apply-templates/>
<xsl:text></p>
</xsl:text>
</xsl:for-each>
</field>
</xsl:if>
</xsl:template>t:\ftemp>type chad.xml <test> <body>content here</body> <body>content there</body> <body>content everywhere</body> </test>
t:\ftemp>xslt chad.xml chad.xsl <?xml version="1.0" encoding="utf-8"?> <field name="body"><![CDATA[<p>content here</p> <p>content there</p> <p>content everywhere</p> ]]></field> t:\ftemp>type chad.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" cdata-section-elements="field"/>
<xsl:template match="body">
<xsl:if test="not(preceding-sibling::body)">
<field name="body">
<xsl:for-each select="../body">
<xsl:text><p></xsl:text>
<xsl:apply-templates/>
<xsl:text></p>
</xsl:text>
</xsl:for-each>
</field>
</xsl:if>
</xsl:template></xsl:stylesheet> t:\ftemp>
-- Upcoming hands-on XSLT, UBL & code list hands-on training classes: Brussels, BE 2009-03; Prague, CZ 2009-03, http://www.xmlprague.cz Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Grouping multiple tags in, Chad Chelius | Thread | RE: [xsl] Grouping multiple tags in, Michael Kay |
| RE: [xsl] Grouping multiple tags in, Michael Kay | Date | [xsl] Merge Similar data nodes usin, Sunder Rajan |
| Month |