Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Create node with outo name

From: sg@-----------.---------.---
To: NULL
Date: 3/6/2005 2:05:00 AM
Thanks Joe, Thats what I was lookinf for. 
This solution brought me to the next problem:
I'm using xsl to transfer WS data (xml) into my xml, and then load it into 
DataTable. I know there is 5 <book> elements (in my destination xml). How can 
I make sure that even if I'll recieve only 2 (from the WS) my XSL will add 
another 3? 
Thanks again,
        sg..

"Joe Fawcett" wrote:

> "sg" <sg@d...> wrote in message 
> news:AA136C57-0D8F-45C3-BCEA-947094A2B31E@m......
> > hi,
> >
> > I have this xml:
> > <root>
> >    <book>
> >        <name>book1</name
> >    </book>
> >    <book>
> >        <name>book1</name
> >    </book>
> >    .
> >    .
> >    .
> > </root>
> >
> > and I'm tring to transfer it to this:
> > <root>
> >    <book1>
> >        <name>book1</name
> >    </book>
> >    <book2>
> >        <name>book1</name
> >    </book>
> >    .
> >    .
> >    <bookn>
> >        <name>book1</name
> >    </book>
> >
> > How can I do this using XSL?
> 
> I wholeheartedly recommend against this, it's very difficult to process this 
> type of markup, you can't easily sort or select all the book(n) elements.
> This would be the stylesheet:
> 
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:template match="/root">
> <xsl:copy>
> <xsl:apply-templates select="book"/>
> </xsl:copy>
> </xsl:template>
> <xsl:template match="book">
> <xsl:element name="{concat('book', position())}">
> <xsl:copy-of select="name"/>
> </xsl:element>
> </xsl:template>
> </xsl:stylesheet>
> 
> I'd prefer:
> 
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:template match="/root">
> <xsl:copy>
> <xsl:apply-templates select="book"/>
> </xsl:copy>
> </xsl:template>
> <xsl:template match="book">
> <book position="{position()}">
> <xsl:copy-of select="name"/>
> </book>
> </xsl:template>
> </xsl:stylesheet>
> 
> Which would give:
> 
> <root>
>   <book position="1">
>     <name>book1</name>
>   </book>
>   <book position="2">
>     <name>book1</name>
>   </book>
> ....
> </root>
> 
> -- 
> 
> Joe (MVP - XML)
> 
> 
> 


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