[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: xsl:key


Subject: Re: xsl:key
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Thu, 22 Jun 2000 11:45:13 +0100


Rhonda Fischer wrote:
...
> 
> My aim is to extract paragraphs from the source tree
> (temp.xml) to be output to a result tree according to
> two criteria:
> 
>       * Target doc="contract" and
>       * Target host="true"
> 
...
> 
>      <Target doc="contract">
>      <Target host="true">
>           <Para>This is a paragraph that will end up in a
>                          contract with hosting customers</Para>
>       </Target>
>       </Target>
> 
...
> 
> <xsl:template match='Para/Target[@doc="contract"
>                          and @host="true"]'>
>   <xsl:element name="{name()}">
>        <xsl:copy-of select="attribute::node()"/>
>        <xsl:apply-templates/>
>    </xsl:element>
> </xsl:template>
...

Rhonda, 

your template match expression says

"single XSL template, seeks Target element with Para parent, and with
two attributes, doc and host, set to 'contract' and 'true' respectively,
for meaningful markup production"

Now your sample XML has two significent mismatches from this:

[1]	the Para element is a *child*, not a parent, of a Target element,
and

[2]	rather than having a single Target element with these two
attributes, you have *two* Target elements, one inside the other, with
one attribute each.

XML allows a single element to have multiple attributes (as long as they
all have different names) so there is no XML reason why you should have
these nested Target elements, though of course someone may be giving
them to you this way.

A simpler solution would be:

temp.xml:
-------------------------------
<Template>

  <Target doc="contract" host="true">
    <Para>This is a paragraph that will end up in a
                   contract with hosting customers</Para>
  </Target>

  <Target doc="advice" host="true">
    <Para>This is a paragraph that will end up in a
                   customer advice document for
                   hosting customers </Para>
  </Target>

</Template>
-------------------------------

temp.xsl:
-------------------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <result>
    <xsl:apply-templates/>
  </result>
</xsl:template>

<!-- copy Targets *and* Para contents -->
<xsl:template match='Target[@doc="contract" and @host="true"]'>
  <xsl:element name="{name()}">
       <xsl:copy-of select="attribute::node()"/>
       <xsl:apply-templates/>
   </xsl:element>
</xsl:template>

<!-- *skip* other Target elements and their contents -->
<xsl:template match="Target">
  <!-- do nothing! -->
</xsl:template>

</xsl:stylesheet>
-------------------------------

(works with instant saxon)

Francis.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords