[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: transforming siblings to a hierarchy
At 2007-09-01 15:13 +0100, John Smith wrote:
How can change the following: What feature of XSLT are you asking about? A solution is below, but I have no idea if that helps you unless you express what it is about XSLT that is preventing you from implementing the answer. It would seem to me that XSLT is not the appropriate language to use for this. What is below is incomplete because you don't say what happens when there are errors. And I'm assuming your sample output above is wrong because you don't indicate anything for <e/>. I hope this helps, but I don't see what this has to do with learning XSLT ... it seems to me to be more of a programming exercise. . . . . . . . . . . . . . Ken
t:\ftemp>type smith.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes"/> <!--start things off with the first operand--> <xsl:template match="ops"> <xsl:apply-templates select="*[1]"/> </xsl:template> <!--operator creates structure--> <xsl:template match="plus"> <xsl:param name="running"/> <xsl:apply-templates select="following-sibling::*[1]"> <xsl:with-param name="running"> <addition> <xsl:copy-of select="$running"/> <xsl:copy-of select="following-sibling::*[1]"/> </addition> </xsl:with-param> </xsl:apply-templates> </xsl:template> <!--operator creates structure--> <xsl:template match="minus"> <xsl:param name="running"/> <xsl:apply-templates select="following-sibling::*[1]"> <xsl:with-param name="running"> <takeaway> <xsl:copy-of select="$running"/> <xsl:copy-of select="following-sibling::*[1]"/> </takeaway> </xsl:with-param> </xsl:apply-templates> </xsl:template> <!--as long as there are still operands, there must be operators--> <xsl:template match="*"> <xsl:param name="running" select="."/> <xsl:choose> <xsl:when test="not(following-sibling::*)"> <xsl:copy-of select="$running"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="following-sibling::*[1]"> <xsl:with-param name="running" select="$running"/> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> t:\ftemp>call xslt smith.xml smith.xsl smith.out t:\ftemp>type smith.out <?xml version="1.0" encoding="utf-8"?> <addition> <addition> <takeaway> <addition> <a/> <b/> </addition> <c/> </takeaway> <d/> </addition> <e/> </addition> t:\ftemp>rem Done!
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|