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

different results with xalan and msxsl/saxon

Subject: different results with xalan and msxsl/saxon
From: "Frank" <fweenink@xxxxxxxxx>
Date: Mon, 18 Feb 2002 10:46:29 +0100
stylename
With following xml file I wanted to create a stylesheet to get
a nested structure. So with heading 2 as a child of heading 1, etc.

<file>
  <p stylename="heading 1">1. title</p>
  <p stylename="Body Text">body text</p>
  <p stylename="Body Text">body text</p>
  <p stylename="heading 2">1.1 title</p>
  <p stylename="Body Text">body text</p>
  <p stylename="Body Text">body text</p>
  <p stylename="List Bullet">list item</p>
  <p stylename="List Bullet">list item</p>
  <p stylename="heading 3">1.1.1 title</p>
  <p stylename="Body Text">body text</p>
  <table>
    <row>
      <cell>
        <p>text</p>
      </cell>
    </row>
  </table>
  <p stylename="Body Text">body text</p>
  <p stylename="heading 2">1.2 title</p>
  <p stylename="Body Text">body text</p>
  <p stylename="Body Text">body text</p>
  <p stylename="heading 1">2. title</p>
  <p stylename="Body Text">body text</p>
  <p stylename="Body Text">body text</p>
  <p stylename="List Bullet">list item</p>
  <p stylename="List Bullet">list item</p>
  <p stylename="heading 2">2.1 title</p>
  <p stylename="Body Text">body text</p>
</file>

So I made this stylesheet:

<!-- key for selecting the p and table elements between the headings -->
<xsl:key name="body-text" match="file/node()[not(starts-with(@stylename,
'heading')) or not(@stylename)]"
  use="preceding-sibling::p[starts-with(@stylename, 'heading')][1]"/>

<!-- selecting the headings with one level higher than the preceding
heading -->
<xsl:key name="headings" match="file/p[starts-with(@stylename, 'heading')]"
  use="preceding-sibling::p[starts-with(@stylename, 'heading')]
  [substring(@stylename, 9 , 1)=substring(current()/@stylename, 9,
1)-1][1]"/>

<xsl:template match="file">
  <xsl:copy>
    <xsl:apply-templates select="p[starts-with(@stylename, 'heading 1')]"/>
  </xsl:copy>
</xsl:template>

<!-- match all headings for recursiveness(is that good English?) -->
<xsl:template match="p[starts-with(@stylename, 'heading')]">
    <xsl:variable name="level" select="substring(@stylename, 9, 1)"/>
    <section>
      <titel><xsl:apply-templates select="@stylename"/><xsl:value-of
select="."/></titel>
      <body>
        <xsl:for-each select="key('body-text', current())">
          <xsl:apply-templates select="current()"/>
        </xsl:for-each>
      </body>
      <xsl:for-each select="key('headings', current())">
        <xsl:apply-templates select="current()"/>
      </xsl:for-each>
    </section>
</xsl:template>

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

With xalan 2.2 D14 I got a good result, but with msxsl and saxon the
stylesheet
only selected heading 1.

xalan:

<section>
<titel stylename="heading 1">1. title</titel>
<body>
  <p stylename="Body Text">body text</p>
  <p stylename="Body Text">body text</p>
  </body>
<section>
<titel stylename="heading 2">1.1 title</titel>
<body>
  <p stylename="Body Text">body text</p>
  <p stylename="Body Text">body text</p>
  <p stylename="List Bullet">list item</p>
  <p stylename="List Bullet">list item</p>
  </body>
<section>
<titel stylename="heading 3">1.1.1 title</titel>
..................... etc.

msxsl, saxon:

<file>
<section>
<titel stylename="heading 1">1. title</titel>
<body>
  <p stylename="Body Text">body text</p>
  <p stylename="Body Text">body text</p>
  </body>
</section>
<section>
<titel stylename="heading 1">2. title</titel>
<body>
  <p stylename="Body Text">body text</p>
  <p stylename="Body Text">body text</p>
  <p stylename="List Bullet">list item</p>
  <p stylename="List Bullet">list item</p>
  </body>
</section>
</file>

Is xalan going rong here? And is there a better way to handle this?




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


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.