xsl-list
[Top] [All Lists]

Re: [xsl] Copying parent nodes with different selection of their content

2007-04-25 08:50:43
David Carlisle wrote:
<xsl:template match="Body">
      <xsl:variable name="x" 
select="Document/*[starts-with(name(),'Make-Toute-Seul-')]"/>
      <xsl:copy>
        <xsl:for-each select="$x">
          <Document>
            <xsl:copy-of select="(../* except $x)|."/>
          </Document>
        </xsl:for-each>
      </xsl:copy>

That's great (and quick)! It works like a charm. fn:starts-with() was expected in any solution because of the chosen names in my example, but I actually need a union of named nodes. Funny I never thought of using the 'except' operator though, indeed: now it is fairly simple....

For any a reason I try to avoid using for-each, but you put me in the right direction for doing the same trick with only a pull (or was it push?) model. I now use a variant of this which places the special cases to the root level, which eases maintenance, I hope:

<xsl:key name="t" match="Make-Toute-Seul-1 | Make-Toute-Seul-2 | Make-Toute-Seul-3" use="''" />

<xsl:template match="/">
   <xsl:apply-templates select="$copy-me/*"/>
</xsl:template>

<xsl:template match="Body">
   <xsl:copy>
       <xsl:apply-templates select="key('t', '')" />
   </xsl:copy>
</xsl:template>

<xsl:template match="key('t', '')">
   <Document>
       <xsl:copy-of select="(../* except key('t', ''))|."/>
   </Document>
</xsl:template>

<xsl:template match="* | @*">
   <xsl:copy>
       <xsl:apply-templates select="node() | @*" />
   </xsl:copy>
</xsl:template>


Thanks!

Abel


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--