xsl-list
[Top] [All Lists]

Re: [xsl] XSL support of Bottom up transformations?

2007-11-14 05:45:40
--On Wednesday, November 14, 2007 04:28:09 PM +0530 Raghu Narayan Koratagere wrote:

I have specific business requirement where I need to transform the
source tree bottom up. The reason being certain attribute of the
parent node gets its value from a similarly caluclated child node. i.e
I need to calculate a derived attribute of a child node before I can
calculate the parent node's attribtue.

Is such a requirement be addressed using XSL? If yes any pointers will
be very helpful.

Is this the sort of thing you mean? Note that this is an XSLT2 transform:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
   <xsl:output indent="yes"/>
   <xsl:template match="node()">
       <xsl:variable name="children" as="node()*">
           <xsl:apply-templates/>
       </xsl:variable>
       <xsl:copy>
           <xsl:sequence select="@*"/>
           <xsl:sequence select="($children/@a)[1]"/>
           <xsl:sequence select="$children"/>
       </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

with input

<?xml version="1.0" encoding="UTF-8"?>
<x>
   <y>
       <z a="1" b="1"/>
   </y>
   <y>
       <z a="2" c="2"/>
   </y>
</x>

gives output

<?xml version="1.0" encoding="UTF-8"?>
<x a="1">
   <y a="1">
       <z a="1" b="1"/>
   </y>
   <y a="2">
       <z a="2" c="2"/>
   </y>
</x>

--
Owen Rees; speaking personally, and not on behalf of HP.
========================================================
Hewlett-Packard Limited.   Registered No: 690597 England
Registered Office:  Cain Road, Bracknell, Berks RG12 1HN

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>