[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: moving an element and then converting it to an at
At 2012-08-15 14:13 -0400, Jonina Dames wrote:
Hi, I'm pretty new to XSLT and I'm having some trouble with a project. You are thinking procedurally and not declaratively. You need to copy your input to the output and indicate when creating each point of your output the things you need from the input. Can anyone help me with this? I'm just using version 1, not 2. I hope the example below helps. Check out some of the diagrams in chapter 1 of the free XSLT book I have made available with its complete content through the links found at: http://www.CraneSoftwrights.com/training/#ptux . . . . . . . . . . Ken ~/t/ftemp $ cat jonina.xml <?xml version="1.0" encoding="UTF-8"?> <media.block id="fun1"> <caption> <para> <txt> <image-size> spread </image-size> </txt> </para> </caption> <media filename="1234567"/> </media.block> ~/t/ftemp $ ~/t/ftemp $ ~/t/ftemp $ xslt jonina.xml jonina.xsl <?xml version="1.0" encoding="utf-8"?><media.block id="fun1"> <caption> <para> <txt> <image-size> spread </image-size> </txt> </para> </caption> <media filename="1234567" image-size="spread"/> </media.block>~/t/ftemp $ ~/t/ftemp $ ~/t/ftemp $ ~/t/ftemp $ cat jonina.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="media"> <!--preserve the element--> <xsl:copy> <!--preserve the existing attributes--> <xsl:copy-of select="@*"/> <!--add the desired attributes--> <xsl:attribute name="image-size"> <xsl:value-of select="normalize-space(../caption/para/txt/image-size)"/> </xsl:attribute> <!--handle any children that may exist; they probably don't for this--> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="@*|node()"><!--identity for all other nodes--> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>~/t/ftemp $
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|