Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Help with XSLT please

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 6/17/2008 1:12:00 PM

KP wrote:
> Sorry I made a small mistake in the XML - it should have been:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <document>
> 	<index><![CDATA[<div class="index">]]>
> 		<partref/><partref/><![CDATA[</div>]]>
> 	</index>
> 	<part>
> 		Part1
> 	</part>
> 	<part>
> 		Part2
> 	</part>
> </document>
> 
> The XSL example almost does what I want but I need the CDATA elements
> to be taken from the XML and not "hard-coded" into the XSL. This is a
> simplification of a much larger XML/XSL but demonstrates the simple
> problem I am trying to solve.

You should fix the input XML as otherwise the problem is not so simple 
to solve, you need disable-output-escaping:

<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   version="1.0">

   <xsl:output method="html"/>

   <xsl:template match="/document">
     <xsl:apply-templates select="index/node()"/>
   </xsl:template>

   <xsl:template match="index/text()">
     <xsl:value-of select="." disable-output-escaping="yes"/>
   </xsl:template>

   <xsl:template match="index/partref">
     <xsl:value-of 
select="normalize-space(../../part[count(current()/preceding-sibling::partref) 
+ 1])"/>
   </xsl:template>

</xsl:stylesheet>


Note that disable-output-escaping is an optional serialization feature 
meaning it is not supported by all XSLT processors in all scenarios. 
Mozilla/Firefox for instance does not support it as it does not 
serialize the result tree.



-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent