RE: [xsl] parameter getting lost in tunnel?

Subject: RE: [xsl] parameter getting lost in tunnel?
From: "Tom Schmitter" <toms@xxxxxxxxxxxxxxxxx>
Date: Mon, 21 Jul 2008 16:54:58 -0700 (PDT)
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 level="0">
	<A level="1">
		<B level="2"></B>
		<B level="2">
			<C level="3"></C>


<xsl:template match="@* | node()" >
	<xsl:param name="depth" select="0" />
		<xsl:attribute name="level" select="$depth" />
		<xsl:apply-templates select="@* | node()" >
			<xsl:with-param name="depth" select="$depth+1" />

(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"/>

This almost works, but I seem to missing some terminating conditions which
cause terminal elements to close properly:


(note the <B/> and <C/> tags)

Again, any hints are much appreciated.


Current Thread