[Home] [By Thread] [By Date] [Recent Entries]
At 2012-01-13 10:48 -0500, I wrote:
At 2012-01-13 14:41 +0000, Fabien Tillier wrote:I have the two following sequences I didn't give you the result as a variable, only as output. The example below gives you a variable of strings you can then work with. I hope this helps. . . . . . . Ken T:\ftemp>xslt2 fabien.xsl fabien.xsl N112,N100,N107,P2010,N109,P2014,P2015,N108,N203,N206,N307,N311 N112,N100,P2014,P2015,N108,N203,N306,N206,N307,N311 N112,N100,N107,P2010,N109,P2014,P2015,N108,N203,N306,N206,N307,N311 T:\ftemp>type fabien.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="2.0"> <xsl:output method="text"/> <xsl:template match="/"> <!--input sequences--> <xsl:variable name="seq1" select="tokenize('N112 N100 N107 P2010 N109 P2014 P2 015 N108 N203 N206 N307 N311','\s+')"/> <xsl:variable name="seq2" select="tokenize('N112 N100 P2014 P2015 N108 N203 N3 06 N206 N307 N311','\s+')"/> <!--order them with information about their position in other sequence-->
<xsl:variable name="items1">
<xsl:for-each select="$seq1">
<item index="{position()}" other="{index-of($seq2,.)[1]}">
<xsl:value-of select="."/>
</item>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="items2">
<xsl:for-each select="$seq2">
<item index="{position()}" other="{index-of($seq1,.)[1]}">
<xsl:value-of select="."/>
</item>
</xsl:for-each>
</xsl:variable><xsl:variable name="seq" as="xsd:string*"> <!--order the result based on relative positions--> <xsl:for-each select="$items1/item,$items2/item[@other='']"> <xsl:sort select="(:the relative order is latest of self or other:) max((number(@index), if(@other='') (:if no other, then use previous other:) then preceding-sibling::*[@other!=''][1]/number(@other) else number(@other)))"/> <xsl:sequence select="."/> </xsl:for-each> </xsl:variable> <!--reveal inputs and outputs--> <xsl:value-of select="$seq1" separator=","/><xsl:text>
</xsl:text> <xsl:value-of select="$seq2" separator=","/><xsl:text>
</xsl:text> <xsl:value-of select="$seq" separator=","/><xsl:text>
</xsl:text> </xsl:template> </xsl:stylesheet> T:\ftemp> -- Contact us for world-wide XML consulting and instructor-led training Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0 http://ude.my/uoui9h Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|

Cart



