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: Wed, 30 Apr 2008 16:16:50 -0700 (PDT),    group: microsoft.public.xml        back       


XSLT question   
XSL noob here -

I have XML similar to the following:

<response>
<a>
<b>
<c id="1">data</c>
<c id="2">data</c>
<c id="3">data</c>
<c id="4">data</c>
</b>
</a>
</response>

I want to transform the XML so that the result is the same except one
of the c nodes is always returned first in the response based on a
specfic id element (see below).

<response>
<a>
<b>
<c id="3">data</c>
<c id="1">data</c>
<c id="2">data</c>
<c id="4">data</c>
</b>
</a>
</response>

Seems like it should be simple to do, but I can't figure it out the
right syntax.  Can anyone help?
date: Wed, 30 Apr 2008 16:16:50 -0700 (PDT)   author:   unknown

Re: XSLT question   
time2fly@gmail.com wrote:

> I want to transform the XML so that the result is the same except one
> of the c nodes is always returned first in the response based on a
> specfic id element (see below).

Pass in the id of the 'c' element as a parameter and then use the 
identity transformation template plus a template for 'b' elements that 
ensures that the 'c' children are processed in the order you want:

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

   <xsl:param name="id" select="3"/>

   <xsl:strip-space elements="*"/>

   <xsl:output method="xml" indent="yes"/>

   <xsl:template match="@* | node()">
     <xsl:copy>
       <xsl:apply-templates select="@* | node()"/>
     </xsl:copy>
   </xsl:template>

   <xsl:template match="b">
     <xsl:copy>
       <xsl:apply-templates select="@*"/>
       <xsl:apply-templates select="c[@id = $id]"/>
       <xsl:apply-templates select="c[not(@id = $id)]"/>
     </xsl:copy>
   </xsl:template>

</xsl:stylesheet>

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Thu, 01 May 2008 13:11:42 +0200   author:   Martin Honnen

Re: XSLT question   
On May 1, 4:11 am, Martin Honnen  wrote:
> time2...@gmail.com wrote:
> > I want to transform the XML so that the result is the same except one
> > of the c nodes is always returned first in the response based on a
> > specfic id element (see below).
>
> Pass in the id of the 'c' element as a parameter and then use the
> identity transformation template plus a template for 'b' elements that
> ensures that the 'c' children are processed in the order you want:
>
> <xsl:stylesheet
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    version="1.0">
>
>    <xsl:param name="id" select="3"/>
>
>    <xsl:strip-space elements="*"/>
>
>    <xsl:output method="xml" indent="yes"/>
>
>    <xsl:template match="@* | node()">
>      <xsl:copy>
>        <xsl:apply-templates select="@* | node()"/>
>      </xsl:copy>
>    </xsl:template>
>
>    <xsl:template match="b">
>      <xsl:copy>
>        <xsl:apply-templates select="@*"/>
>        <xsl:apply-templates select="c[@id = $id]"/>
>        <xsl:apply-templates select="c[not(@id = $id)]"/>
>      </xsl:copy>
>    </xsl:template>
>
> </xsl:stylesheet>
>
> --
>
>         Martin Honnen --- MVP XML
>        http://JavaScript.FAQTs.com/

This worked perfectly, thanks!
date: Thu, 1 May 2008 15:46:08 -0700 (PDT)   author:   unknown

Google
 
Web ureader.com


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