[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How does one merge sequences?
Hi Kenneth, > ....indicating that the "merged" sequence is still recognized as two > sequences instead of a single merged one. How can one do a proper > merge? It's not that the sequences are still separate, as such. In your code, you create a sequence of five elements, two from one document and three from another. Just because the sequence contains all those elements doesn't mean that they've been moved into another document. Importantly, they still have their original siblings. So if you do: count(preceding-sibling::item) = 0 then it's true for two elements: the first element in the first document and the first element in the second document. If you want to create a new document that contains all the elements from both documents, then you can do something like: <xsl:variable name="merged"> <xsl:sequence select="$seq1/* | $seq2/*" /> </xsl:variable> Note that the elements in the new document are *copies* of the elements from the original documents. If you want to create the sequence of the original elements, as in: <xsl:variable name="merged" select="$seq1/* | $seq2/*" /> and test whether you're on the first one in that sequence, then use the position() function: <xsl:for-each select="$merged"> <xsl:value-of select="." /> <xsl:if test="position() = 1"> = first</xsl:if> <xsl:text>
</xsl:text> </xsl:for-each> By the way, note that if you merge sequences with the union operator then there's no guarantee that the elements from the first document you create will actually be before the elements from the second document you create in the sequence. (Per the spec, the order has to be consistent throughout the transformation but it's implementation dependent what the ordering of nodes from different documents actually is.) So if you care about the order of the elements in the merged sequence, it's better to use the "," operator to merge the sequences, as in: $seq1/*, $seq2/* Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/
|
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
|