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

Re: another placement of nodes question

Subject: Re: another placement of nodes question
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 26 Jan 2010 15:50:06 +0100
Re:  another placement of nodes question
a kusa wrote:

Thank you for your input.The issue I am having here is when I use
level2/item[last()], the processor considers both item elements under
<level2> as last ones. So I still get repeated <spec> elements under
both item elements.

I can't reproduce that. When I transform


<root>
<level1>
<st1>
<desc><text>sample desc</text></desc>
<!-- A <spec> element can occur here as well-->
<level2>
<item><text>r1 </text></item>
<item><text>r2</text></item>
</level2>
<spec><para>Some spec 1</para></spec>
<spec><para>Some spec 2</para></spec>
</st1>
</level1>
</root>

with the stylesheet I posted, which is

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

  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

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

  <xsl:template match="st1/desc | st1/level2">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="level1">
    <step1>
      <xsl:apply-templates select="st1/*"/>
    </step1>
  </xsl:template>

  <xsl:template match="level2/item">
    <step2>
      <xsl:apply-templates/>
    </step2>
  </xsl:template>

  <xsl:template match="level2/item[last()]" priority="3">
    <step2>
      <xsl:apply-templates/>
      <xsl:copy-of select="../following-sibling::spec"/>
    </step2>
  </xsl:template>

<xsl:template match="st1/spec"/>

</xsl:stylesheet>

then I get the following output:

<root>
   <step1>
      <text>sample desc</text>
      <step2>
         <text>r1 </text>
      </step2>
      <step2>
         <text>r2</text>
         <spec>
            <para>Some spec 1</para>
         </spec>
         <spec>
            <para>Some spec 2</para>
         </spec>
      </step2>
   </step1>
</root>

with both Saxon 6.5 and Saxon 9.2.

Which processor did you use that gives you a different result?

--

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.