Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Replacing a string with another nodes text.

From: "siac99" <simonwatt@-----.--->
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.
> > 
> >



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