Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XML and XSLT

From: Phil Lanch <phil@--------------->
To:
Date: 3/2/2000 9:13:00 PM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent