Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - RE: Replacing a string with another nodes text. [Thread Next] Re: Replacing a string with another nodes text.To: NULL Date: 4/4/2006 11:20:00 PM
Thank you so much. That worked a treat and solved my problem. I really
appreciate it. Thanks :)
Mukul Gandhi wrote:
> Please try this stylesheet
>
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
> <xsl:output method="xml" indent="yes" />
>
> <xsl:template match="/root">
> <root>
> <xsl:for-each select="book">
> <book>
> <xsl:for-each select="*">
> <xsl:element name="{name()}">
> <xsl:choose>
> <xsl:when test="contains(., 'answerTo')">
> <xsl:value-of select="../../answers/answer[@id =
> substring-after(current(), 'answerTo')]" />
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="." />
> </xsl:otherwise>
> </xsl:choose>
> </xsl:element>
> </xsl:for-each>
> </book>
> </xsl:for-each>
> </root>
> </xsl:template>
>
> </xsl:stylesheet>
>
> Regards,
> Mukul
>
> "siac99" wrote:
>
> > I want to turn this:
> >
> > <root>
> > <book>
> > <name>answerToce02dde2-07a5-4a7a-9c72-51e97c13af8d</name>
> > <author>answerTo47f8c10a-2032-4de3-9862-6056850f8002</author>
> > <year>1986</year>
> > </book>
> >
> > <answers>
> > <answer id="ce02dde2-07a5-4a7a-9c72-51e97c13af8d">Xslt for
> > dummies</answer>
> > <answer id="47f8c10a-2032-4de3-9862-6056850f8002">Bob</answer>
> > </answers>
> > </root>
> >
> > Into this:
> >
> > <root>
> > <book>
> > <name>Xslt for dummies</name>
> > <author>Bob</author>
> > <year>1986</year>
> > </book>
> > </root>
> >
> > In summary: I want to find the element 'book', and for each of its
> > nodes see if it contains the string 'answerTo'. If it does
> >
> > then replace the nodes text with the text of the element 'answer' whos
> > Id attribute mathches the 32 characters next to the 'answerTo' string.
> >
> > Is is possible to do this with XSLT? If so then how? Can someone point
> > me in the right direction please?
> >
> > Cheers, any help is appreciated.
> >
> >
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
