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

Re: XML and XSLT

Subject: Re: XML and XSLT
From: Phil Lanch <phil@xxxxxxxxxxxxxxx>
Date: Thu, 02 Mar 2000 21:13:29 +0000
xsl prop
Matt.Varney@xxxxxxxxx wrote:
> 
> I would like to use XSTL to transform one XML doc (call it "A") into a new
> XML doc (call it "B"):
> 
> Here is "A":
> 
> <?xml version="1.0"?>
> <dsobjects>
>         <prop>
>                 <title>President's Office Staff</title>
>                 <summary>Financial Reports for President's Office
> Staff</summary>
>         </prop>
>         <prop>
>                 <title>VP of Finance</title>
>                 <summary>Financial Reports for VP of Finance</summary>
>         </prop>
>                 <title>VP of External Affairs</title>
>                 <summary>Financial Reports for VP of External
> Affairs</summary>
>         </prop>
>         <prop>
>                 <title>VP of Internal Affairs</title>
>                 <summary>Financial Reports for VP of Internal
> Affairs</summary>
>         </prop>
> ...etc...........
> <dsobjects>
> 
> And here is "B":
> 
> <?xml version="1.0"?>
> <dsobjects>
>         <dsobject type="Collection" handle="Collection-100">
>                 <prop>
>                         <title>President's Office Staff</title>
>                         <summary>Financial Reports for President's Office
> Staff</summary>
>                 </prop>
>         </dsobject>
>         <dsobject type="Collection" handle="Collection-101">
>                 <prop>
>                         <title>VP of Finance</title>
>                         <summary>Financial Reports for VP of
> Finance</summary>
>                 </prop>
>         </dsobject>
>         <dsobject type="Collection" handle="Collection-102">
>                 <prop>
>                         <title>VP of External Affairs</title>
>                         <summary>Financial Reports for VP of External
> Affairs</summary>
>                 </prop>
>         </dsobject>
>         <dsobject type="Collection" handle="Collection-103">
>                 <prop>
>                         <title>VP of Internal Affairs</title>
>                         <summary>Financial Reports for VP of Internal
> Affairs</summary>
>                 </prop>
>         </dsobject>
> 
> ......etc......
> 
> </dsobjects>
> 
> As you can see, the "B" sample adds a counting element to identify each
> individual "dsobject type".  There will be several hundred of these to tag
> with a sequential number.
> 
> Can anyone help suggest the syntax of the XSL doc to apply against XML Doc
> "A" to produce XML doc "B"?

<xsl:template match="dsobjects|title|summary">
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="prop">
  <dsobject type="Collection">
    <xsl:attribute name="handle">Collection-<xsl:value-of select="100 +
count(preceding-sibling::prop)"/></xsl:attribute>
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </dsobject>
</xsl:template>

-- 

cheers

phil

"The smile Ulrich gave him in answer said: I don't know;
let me wait and see what more you have to say."  Musil


 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.