[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:key

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

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>


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,

[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:


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

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


<xsl:stylesheet version="1.0"

<xsl:template match="/">

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

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


(works with instant saxon)


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

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.