[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Value dependency between nested attributes
At 2009-10-18 02:19 +0200, xyz xyz wrote:
Output format shall be same than input format (XML-->XML Transformation): Yes, this is what you need to work with. Below I've given you two approaches, one for where the name="a" and one for where the name="b". For reasons of good style you should consistently use the same approach, but I've given you both so you can decide which is more appropriate for your final solution. The first approach catches the <A> and then reconstitutes the <A> and the required attributes. The second approach catches only the attributes that need changing and reconstitute only the attributes. I hope this helps. . . . . . . . . . . Ken T:\ftemp>type karl.xml <test> <A name="a" test1="vw" test2="cd" test3="ef" test4="gh"/> <A name="b" test1="vw" test2="cd" test3="ef" test4="gh" test7="ee"/> <A name="c" test1="vw" test2="cd" test3="ef" test4="gh"/> <A name="d" test1="xy" test2="ij" test3="kl" test4="mn" test5="op"/> </test> T:\ftemp>xslt karl.xml karl.xsl <?xml version="1.0" encoding="utf-8"?><test> <A name="a" test1="vw" test2="XXX" test3="YYY" test4="gh"/> <A name="b" test1="vw" test2="VVV" test3="WWW" test4="gh" test7="ee"/> <A name="c" test1="vw" test2="cd" test3="ef" test4="gh"/> <A name="d" test1="xy" test2="ij" test3="kl" test4="mn" test5="op"/> </test> T:\ftemp>type karl.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:param name="XX">XXX</xsl:param> <xsl:param name="YY">YYY</xsl:param> <xsl:param name="VV">VVV</xsl:param> <xsl:param name="WW">WWW</xsl:param> <!--method one: testing and reconstituting the element--> <xsl:template match="A[@name='a']"> <xsl:copy> <!--preserve all attributes--> <xsl:apply-templates select="@*"/> <!--overwrite the attributes needing changing--> <xsl:attribute name="test2"><xsl:value-of select="$XX"/></xsl:attribute> <xsl:attribute name="test3"><xsl:value-of select="$YY"/></xsl:attribute> <!--act on the children--> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> <!--method two: acting only on the attributes--> <xsl:template match="A[@name='b']/@test2"> <xsl:attribute name="test2"><xsl:value-of select="$VV"/></xsl:attribute> </xsl:template> <xsl:template match="A[@name='b']/@test3"> <xsl:attribute name="test3"><xsl:value-of select="$WW"/></xsl:attribute> </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> -- Upcoming: hands-on code list, UBL, XSLT, XQuery and XSL-FO classes in Copenhagen Denmark and Washington DC USA, October/November 2009 Interested in other classes? http://www.CraneSoftwrights.com/s/i/ Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|
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
|