Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: XML and XSLT

From: Matt.Varney@---------
To:
Date: 3/2/2000 11:23:00 AM
Thanks, Mike.

Sorry about the typo (XSTL....  Doh!!).

As for the rest, I will look it over and give it a try.  As you no doubt
surmised, I am new to XML and XSLT and I really do appreciate your help.  

Sorry again for the typo and the "cardinal sin"....



-----Original Message-----
From: Mike Brown [mailto:mbrown@xxxxxxxxxxxxx]
Sent: Thursday, March 02, 2000 3:36 PM
To: 'xsl-list@xxxxxxxxxxxxxxxx'
Cc: 'Matt.Varney@xxxxxxxxx'
Subject: RE: XML and XSLT


> I would like to use XSTL to transform one XML doc
[...snip...]
>
> <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>
[...snip...]
> <dsobjects>
> 
> <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>
[...snip...]
> </dsobjects>

Sorry to nitpick, but...

1. it's XSLT, not XSTL.

2. XSLT reads from and creates intangible node trees that *may* (and usually
are) derived from literal XML documents, and *may* emit the new tree as an
XML document, but you will get in trouble if you think of it as a language
that acts directly on documents themselves.

3. you didn't mention which XSL processor you are using, a cardinal sin on
this list due to the differences between the language-known-as-xsl-in-ie5
and real XSLT.

If you're using real XSLT, the answer will probably have these templates in
it:

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

<xsl:template match="*">
  <!-- for any element not otherwise matched, copy it -->
  <xsl:copy>
    <!-- add to copied element its attributes and children -->
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="prop">
  <!-- make a number for this 'prop' element -->
  <xsl:variable name="propnum">
    <xsl:number level="any"/>
  </xsl:variable>
  <!-- make a 'dsobject' element with a fixed attribute -->
  <dsobject type="Collection">
    <!-- generate its variable attribute -->
    <xsl:attribute name="handle">
      <xsl:value-of select="concat('Collection-',string(100 +
number($propnum)))"/>
    </xsl:attribute>
    <!-- add to 'dsobject' a child 'prop' -->
    <xsl:copy>
      <!-- add to 'prop' its attributes and children -->
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </dsobject>
</xsl:template>


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


transparent
Print
Mail
Digg
delicious
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