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

RE: Simple list -> Nested list based on attribute valu

Subject: RE: Simple list -> Nested list based on attribute values
From: cknell@xxxxxxxxxx
Date: Thu, 19 Aug 2004 14:16:13 -0400
xsl select based on attribute
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" encoding="UTF-8" />
  <xsl:strip-space elements="*" />

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

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

  <xsl:template match="item[@header]">
    <xsl:variable name="index" select="count(preceding-sibling::item[@header])" />
    <section title="{.}">
      <xsl:apply-templates select="following-sibling::item[not(@header)]"><xsl:with-param name="location" select="$index" /></xsl:apply-templates>
    </section>
  </xsl:template>

  <xsl:template match="item[not(@header)]">
    <xsl:param name="location" />
    <xsl:if test="count(preceding-sibling::item[@header]) = $location + 1">
      <item><xsl:value-of select="." /></item>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>
-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     <jhaines@xxxxxxxxxxxxxxxxxx>
Sent:     Thu, 19 Aug 2004 18:48:42 +0200
To:       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject:   Simple list -> Nested list based on attribute values

I have an XML document of the form
 
<doc>
  <item header='true'>Section 1</item> 
  <item>Section 1.1</item> 
  <item>Section 1.2</item>
 
  <item header='true'>Section 2</item> 
  <item>Section 2.1</item> 
  <item>Section 2.2</item>
</doc>
 
that I want to transform to the following:
 
<doc>
  <section title="Section 1">
    <item>Section 1.1</item> 
    <item>Section 1.2</item>
  </section>
 
  <section title="Section 2">
    <item>Section 2.1</item> 
    <item>Section 2.2</item>
  </section>
</doc>
 
I was able to match the @header <item>s with the rule 'item[@header  "true"]' but couldn't work out a predicate to match "all subsequent
<item>s up until the next @header <item>".
 
Jason
 


Any information in this communication is confidential and may be privileged or otherwise protected from disclosure without our consent. If you are not the intended recipient, you are not authorised to and must not disclose, copy, distribute, or retain this message or any part of it. You are requested to please telephone or email the sender and delete this message and any attachment from your system.
	
Due to the electronic nature of e-mail, there is a risk that the information contained in this message has been modified. Consequently we can accept no responsibility or liability as to the completeness or accuracy of the information.
    
A-03-03-E

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.