Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Sat, 7 Jun 2008 11:01:55 -0700 (PDT),    group: microsoft.public.xsl        back       


Help with XSLT please   
Hi All,

The following XML fragment is a simplification of a problem I'm trying
to solve.

<?xml version="1.0" encoding="UTF-8"?>
<document>
	<index><![CDATA[<div class="index">]]>
		<partref/><![CDATA[</div>]]>
		<partref/>
	</index>
	<part>
		Part1
	</part>
	<part>
		Part2
	</part>
</document>

I want to render this as

<div class="index>Part1Part2</div>

Can anyone give me a start on the XLS for this please?

Thanks in advance,

Kirk
date: Sat, 7 Jun 2008 11:01:55 -0700 (PDT)   author:   KP

Re: Help with XSLT please   
KP wrote:

> The following XML fragment is a simplification of a problem I'm trying
> to solve.
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <document>
> 	<index><![CDATA[<div class="index">]]>
> 		<partref/><![CDATA[</div>]]>
> 		<partref/>
> 	</index>
> 	<part>
> 		Part1
> 	</part>
> 	<part>
> 		Part2
> 	</part>
> </document>
> 
> I want to render this as
> 
> <div class="index>Part1Part2</div>

Are you sure the 'Part2' belongs inside of the div element? Because 
above the second 'partref' is outside of the (escaped) div.

It is also not clear where the 'div class="index"' comes from, whether 
it comes from the 'index' element or from the escaped 'div' element.

Assuming you want to transform the 'index' element into a 'div 
class="index"' element then you can use


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

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

   <xsl:template match="index">
     <div class="index">
       <xsl:apply-templates select="*"/>
     </div>
   </xsl:template>

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

   <xsl:template match="part">
     <xsl:value-of select="normalize-space(.)"/>
   </xsl:template>

</xsl:stylesheet>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Sun, 08 Jun 2008 13:00:11 +0200   author:   Martin Honnen

Re: Help with XSLT please   
"KP"  wrote in message 
news:f26409bd-f282-4a32-9747-abeba725f5c1@c58g2000hsc.googlegroups.com...
> Hi All,
>
> The following XML fragment is a simplification of a problem I'm trying
> to solve.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <document>
> <index><![CDATA[<div class="index">]]>
> <partref/><![CDATA[</div>]]>
> <partref/>
> </index>
> <part>
> Part1
> </part>
> <part>
> Part2
> </part>
> </document>
>
> I want to render this as
>
> <div class="index>Part1Part2</div>
>
> Can anyone give me a start on the XLS for this please?
>
> Thanks in advance,
>
> Kirk
That XML is an abomination.
When you say you want to render as:
<div class="index>Part1Part2</div>
do you mean that the div class="index" is always like that or are you taking 
it from the CDATA section without the <partref/> text?
Is there any additional logic as to which part elements' contents are 
include or is it just all of them?

-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
date: Sun, 8 Jun 2008 12:02:34 +0100   author:   Joe Fawcett am

Re: Help with XSLT please   
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.

Thanks for your input,

Kirk
date: Mon, 16 Jun 2008 14:23:14 -0700 (PDT)   author:   KP

Re: Help with XSLT please   
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/
date: Tue, 17 Jun 2008 13:11:43 +0200   author:   Martin Honnen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us