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

Re: Newbie Q: Style sheet for simple transform

Subject: Re: Newbie Q: Style sheet for simple transform
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Wed, 05 Jun 2002 23:53:49 +0200
xsl simple copy stylesheet
<xsl:template match="node()">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="agency">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()[not(starts-with(name(), 'custom_label'))] | *[starts-with(name(), 'custom_label')][1]"/>
</xsl:copy>
</xsl:template>


<xsl:template match="*[starts-with(name(), 'custom_label')]">
<custom_labels>
<xsl:copy-of select=". | following-sibling::*[starts-with(name(), 'custom_label')]"/>
</custom_labels>
</xsl:template>


If you remove the numbers from the element names, you can simplify the stylesheet a lot.

Joerg


Richard Rowell wrote:
I recieve a XML file structured like so:
<records>
<agencies>
<agency>
<name>Agency name</name> <description>test data - description of agency here</description>
<landmarks>landmark information here</landmarks>
<zips_served> <zip>32215</zip>
<zip>32202</zip>
</zips_served>
...(other data fields)
<custom_label1>customlabel1 name</custom_label1>
<custom_label2>customlabel2 name</custom_label2>
<custom_label3>label3</custom_label3>
<custom_label4>label4</custom_label4>
<custom_label5>label5</custom_label5>
...(other date fields)
</agency>
...(more agency records)
</agencies>
...(other types of records go here)
</records>


I would like to transform this file so that the custom_label fields
are contained in a <custom_labels> record like so:
  ...
  <custom_labels>
   <custom_label1>customlabel1 name</custom_label1>
   <custom_label2>customlabel2 name</custom_label2>
   <custom_label3>label3</custom_label3>
   <custom_label4>label4</custom_label4>
   <custom_label5>label5</custom_label5>
  </custom_labels>
  ...

The rest of the file should just "pass through" unchanged.  I'm positive
this is possible using an XSL processor (in my case Xalan), and I'm
fairly sure it will be very simple... But I'm having a hard time
grasping exactly what the style sheet should look like.

TIA
Richard Rowell
richard@xxxxxxxxxxxxxxxxx


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.