Subject: Re: [xsl] Tricky transformation task From: André Locher <jimmy@xxxxxxxxxxxxxx> Date: Wed, 11 Jul 2007 23:46:44 +0200 |
(list guidelines would suggest that a different subject line would have been better, for teh archives)
Your suggested output seems to be missing some lines, eg (if I understand your input) there is an object 4 as one end of link 18 that isn't listed in your output.
I added an <end/> stop element just to simplify the end of recursion testing (as it's time to go home, mainly)
<LINKS> <LINK ID="2" O1-ID="1" O2-ID="3"/> <LINK ID="10" O1-ID="1" O2-ID="11"/> <LINK ID="14" O1-ID="11" O2-ID="15"/> <LINK ID="18" O1-ID="2" O2-ID="4"/> <LINK ID="22" O1-ID="2" O2-ID="8"/> <LINK ID="26" O1-ID="8" O2-ID="17"/> <end/> </LINKS>
$ saxon8 links.xml links.xsl <?xml version="1.0" encoding="UTF-8"?> <SUBG-ITEMS xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:d="data:,d"> <ITEM SUBG-ID="d1e3" ITEM-ID="1" ITEM-TYPE="O" NAME="Object"/> <ITEM SUBG-ID="d1e3" ITEM-ID="3" ITEM-TYPE="O" NAME="Object"/> <ITEM SUBG-ID="d1e3" ITEM-ID="2" ITEM-TYPE="L" NAME="Link"/> <ITEM SUBG-ID="d1e3" ITEM-ID="11" ITEM-TYPE="O" NAME="Object"/> <ITEM SUBG-ID="d1e3" ITEM-ID="10" ITEM-TYPE="L" NAME="Link"/> <ITEM SUBG-ID="d1e3" ITEM-ID="15" ITEM-TYPE="O" NAME="Object"/> <ITEM SUBG-ID="d1e3" ITEM-ID="14" ITEM-TYPE="L" NAME="Link"/> <ITEM SUBG-ID="d1e9" ITEM-ID="2" ITEM-TYPE="O" NAME="Object"/> <ITEM SUBG-ID="d1e9" ITEM-ID="4" ITEM-TYPE="O" NAME="Object"/> <ITEM SUBG-ID="d1e9" ITEM-ID="18" ITEM-TYPE="L" NAME="Link"/> <ITEM SUBG-ID="d1e9" ITEM-ID="8" ITEM-TYPE="O" NAME="Object"/> <ITEM SUBG-ID="d1e9" ITEM-ID="22" ITEM-TYPE="L" NAME="Link"/> <ITEM SUBG-ID="d1e9" ITEM-ID="17" ITEM-TYPE="O" NAME="Object"/> <ITEM SUBG-ID="d1e9" ITEM-ID="26" ITEM-TYPE="L" NAME="Link"/> </SUBG-ITEMS>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:d="data:,d"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output indent="yes"/>
<xsl:template match="LINKS"> <xsl:apply-templates select="LINK[1]"/> </xsl:template>
<xsl:template match="LINK">
<xsl:param name="r" select="()"/>
<xsl:variable name="ro" select="$r[@ITEM-TYPE='O']"/>
<xsl:choose>
<xsl:when test="@O1-ID=$ro/@ITEM-ID">
<xsl:variable name="L" as="element()">
<ITEM SUBG-ID="{$ro[@ITEM-ID=current()/@O1-ID]/@SUBG-ID}" ITEM-ID="{@ID}" ITEM-TYPE="L" NAME="Link"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="@O2-ID=$ro/@ITEM-ID">
<xsl:apply-templates select="following-sibling::*[1]">
<xsl:with-param name="r" select="$r/d:join(.,current()/@O1-ID,current()/@O2-ID),$L"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="O" as="element()">
<ITEM SUBG-ID="{$ro[@ITEM-ID=current()/@O1-ID]/@SUBG-ID}" ITEM-ID="{@O2-ID}" ITEM-TYPE="O" NAME="Object"/>
</xsl:variable>
<xsl:apply-templates select="following-sibling::*[1]">
<xsl:with-param name="r" select="$r,$O,$L"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="@O2-ID=$ro/@ITEM-ID">
<xsl:variable name="L" as="element()">
<ITEM SUBG-ID="{$ro[@ITEM-ID=current()/@O2-ID]/@SUBG-ID}" ITEM-ID="{@ID}" ITEM-TYPE="L" NAME="Link"/>
</xsl:variable>
<xsl:variable name="O" as="element()">
<ITEM SUBG-ID="{$ro[@ITEM-ID=current()/@O2-ID]/@SUBG-ID}" ITEM-ID="{@O2-ID}" ITEM-TYPE="O" NAME="Object"/>
</xsl:variable>
<xsl:apply-templates select="following-sibling::*[1]">
<xsl:with-param name="r" select="$r,$O,$L"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="L" as="element()">
<ITEM SUBG-ID="{generate-id()}" ITEM-ID="{@ID}" ITEM-TYPE="L" NAME="Link"/>
</xsl:variable>
<xsl:variable name="O1" as="element()">
<ITEM SUBG-ID="{generate-id()}" ITEM-ID="{@O1-ID}" ITEM-TYPE="O" NAME="Object"/>
</xsl:variable>
<xsl:variable name="O2" as="element()">
<ITEM SUBG-ID="{generate-id()}" ITEM-ID="{@O2-ID}" ITEM-TYPE="O" NAME="Object"/>
</xsl:variable>
<xsl:apply-templates select="following-sibling::*[1]">
<xsl:with-param name="r" select="$r,$O1,$O2,$L"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="end">
<xsl:param name="r" select="()"/>
<SUBG-ITEMS>
<xsl:perform-sort select="$r">
<xsl:sort select="@SUBG-ID"/>
</xsl:perform-sort>
</SUBG-ITEMS>
</xsl:template>
<xsl:function name="d:join"> <xsl:param name="e"/> <xsl:param name="i1"/> <xsl:param name="i2"/> <ITEM> <xsl:copy-of select="$e/@*"/> <xsl:if test="$e/@SUBG-ID=$i2"> <xsl:attribute name="SUBG-ID" select="$i1"/> </xsl:if> </ITEM> </xsl:function>
</xsl:stylesheet>
________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Tricky transformation tas, David Carlisle | Thread | RE: [xsl] Tricky transformation tas, Michael Kay |
RE: [xsl] 5 column grid sorted by , cknell | Date | RE: [xsl] Tricky transformation tas, Michael Kay |
Month |