[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Need to override previously copied attributes etc.
Hi, Tempore 02:25:13, die 07/28/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Taco Fleur <taco@xxxxxxxxxxxxx>: I have a stylesheet which basically should do the following: - Copy the whole XML file passed to it - Apply a template if the element is "field" - Copy everything over from the XML file passed - Then start copying everything from the XML in a variable ($fieldCollection) where the attribute "identity" matches - However if the element from $fieldCollection contains an attribute called "reference" is present it needs to copy everything from the element in $fieldCollection that matches that "identity" - Then it just needs to copy over that element from $fieldCollection and overwrite any attributes previously copied - And finally it needs to copy over the element from the XML passed in and overwrite anything previously there
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes" media-type="string" /> <xsl:variable name="fieldCollection" select="document('fieldcollection.xml')/root"/> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates /> </xsl:copy> </xsl:template> <xsl:template match="field"> <xsl:variable name="match" select="$fieldCollection/field[current()/@identity = @identity ]"/> <xsl:copy> <xsl:copy-of select="@*" /> <xsl:apply-templates select="$match" mode="collect_attributes"/> <xsl:copy-of select="*"/> <xsl:apply-templates select="$match" mode="collect_elements"/> </xsl:copy> </xsl:template> <xsl:template match="field" mode="collect_attributes"> <xsl:param name="exclude">-identity-reference-</xsl:param> <xsl:copy-of select="@*[not(contains($exclude,concat('-',local-name(),'-')))]"/> <xsl:apply-templates select="../field[@identity=current()/@reference]" mode="collect_attributes"> <xsl:with-param name="exclude">-identity-reference-name-</xsl:with-param> </xsl:apply-templates> </xsl:template> <xsl:template match="field" mode="collect_elements"> <xsl:copy-of select="*"/> <xsl:apply-templates select="../field[@identity=current()/@reference]" mode="collect_elements"/> </xsl:template> </xsl:stylesheet> regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Vincit omnia simplicitas Keep it simple
|
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
|