[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: parameter getting lost in tunnel?
wow. That was an eye-opener. Thanks very much, Michael. My situation differs slightly in that my input docs consist of normal, hierarchical xml, with these non-hierarchical section headers interspersed throughout. My task is to wrap all of the normal xml in the appropriately nested sections. You seemed pretty definitive in saying in your paper that the xsl:for-each-group instruction is the way to handle such a case, so I'm trying to get my head around that approach. I confess it scares me a bit, so wanted to run it by you, and also ask for help on a lingering problem in the output, if it wouldn't be too much trouble. I think my first task is to add "level" information into all of the existing xml elements so they can be grouped: <doc> <A> <B></B> <B> <C></C> </B> </A> </doc> Becomes: <doc level="0"> <A level="1"> <B level="2"></B> <B level="2"> <C level="3"></C> </B> </A> </doc> Through: <xsl:template match="@* | node()" > <xsl:param name="depth" select="0" /> <xsl:copy> <xsl:attribute name="level" select="$depth" /> <xsl:apply-templates select="@* | node()" > <xsl:with-param name="depth" select="$depth+1" /> </xsl:apply-templates> </xsl:copy> </xsl:template> (more-or-less. the empty elements in this simplified example cause some problems, but that's not material at the moment) Does that seem correct? Then, write the input to the output using the group function (mostly lifted from your paper): <xsl:template name="process-level"> <xsl:param name="population" required="yes" as="element()*"/> <xsl:param name="level" required="yes" as="xs:integer"/> <xsl:for-each-group select="$population" group-starting-with="*[xs:integer(@level) eq $level]"> <xsl:variable name="ename" select="node-name(.)" /> <xsl:element name="{$ename}"> <xsl:call-template name="process-level"> <xsl:with-param name="population" select="current-group()[position() != 1]"/> <xsl:with-param name="level" select="$level + 1"/> </xsl:call-template> </xsl:element> </xsl:for-each-group> </xsl:template> This almost works, but I seem to missing some terminating conditions which cause terminal elements to close properly: <doc> <A> <B/> <B> <C/> </B> </A> </doc> (note the <B/> and <C/> tags) Again, any hints are much appreciated. --Tom
|
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
|