Re: [xsl] copy of specific elements

Subject: Re: [xsl] copy of specific elements
From: Florent Georges <lists@xxxxxxxxxxxx>
Date: Mon, 18 Aug 2008 17:35:40 +0200 (CEST)
henry human wrote:

> Here is the sample. 

  You still don't show the associated output.  I guess your problem is
like the following.  From:

       <e type="author" id="a1"/>
       <e type="author" id="a2"/>
       <e type="author" id="a3"/>
       <e type="section" id="s1"/>
       <e type="section" id="s1"/>

you want to walk through the first two e[@type eq 'author'] (because
there are two e[@type ew 'section']).  You can try the following:

    <xsl:stylesheet xmlns:xsl="";

       <xsl:output indent="yes"/>

       <xsl:template match="/">
             <xsl:variable name="count" select="
                 count(root/e[@type eq 'section'])"/>
             <xsl:apply-templates select="
                 root/e[@type eq 'author'][position() le $count]"/>

       <xsl:template match="e">
          <xsl:element name="{ @id }"/>


  The output is:

    $ saxon hhuman.xml hhuman.xsl
    <?xml version="1.0" encoding="UTF-8"?>

  If the e elements are not all child of the same parent element, use
parenthesis, in order to have the correct position(), like for instance

    (root//e[@type eq 'author'])[position() le $count]



Envoyez avec Yahoo! Mail. Une boite mail plus intelligente

Current Thread