Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Create node with outo name [Thread Next] Re: Create node with outo nameTo: 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)
>
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
