[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to output open/close tags independently?
I don't see what the connection is between trying to coerce XSLT into accepting non-well-formed markup, and grouping. As others have pointed out, the FAQ gives a good example of how to group by a fixed number of elements. For grins, I took your sample and modified it slightly: <?xml version="1.0"?> <batchup> <x>0</x> <x>1</x> <x>2</x> <x>3</x> <x>4</x> <x>5</x> <x>6</x> <x>7</x> <x>8</x> <x>9</x> <x>0</x> <x>1</x> <x>2</x> ... and so on, for 1000 <x> elements. Then I wrote a small stylesheet based on the FAQ method: <xsl:variable name="groupsize" select="3"/> <xsl:template match="/"> <xsl:for-each select="batchup/x[position() mod $groupsize = 1]"> <xsl:text>
</xsl:text> <w> <xsl:copy-of select=".|following-sibling::x[position() < $groupsize]"/> </w> </xsl:for-each> </xsl:template> and another based on a recursive call-template: <xsl:variable name="groupsize" select="3"/> <xsl:template match="/"> <xsl:call-template name="batchup"> <xsl:with-param name="nodes" select="/batchup/x"/> </xsl:call-template> </xsl:template> <xsl:template name="batchup"> <xsl:param name="nodes"/> <xsl:if test="$nodes"> <xsl:text>
</xsl:text> <w> <xsl:copy-of select="$nodes[position() <= $groupsize]"/> </w> <xsl:call-template name="batchup"> <xsl:with-param name="nodes" select="$nodes[position() > $groupsize]"/> </xsl:call-template> </xsl:if> </xsl:template> Not surprisingly, the second transform took about 5 times longer to run (83.34 seconds on w2k/saxon6.5.1/750mhz) than the first one (17.46 seconds) (and Windows complained about my virtual memory usage). Not to mention that the first transform is a smaller amount of code. - Mitch Edward L. Knoll wrote: I am creating a XSL stylesheet which effectively copies an input XML stream to the output and introduces a level of XML elements for a selected set of elements. The problem I have run into is that there does seem to be way to output the open tag of an element separately from the closing tag. I've come up with something which works using to output the open and close tags; in short, I have to hide the fact I'm outputting elements. I am generating well-formed XML, however, I can't seem to come up with a method which allows the elements to be recognized as such while keeping the XSL well-formed. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|