Subject: Re: [xsl] Need to override previously copied attributes etc. From: "Joris Gillis" <roac@xxxxxxxxxx> Date: Thu, 28 Jul 2005 17:50:21 +0200 |
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
In Saxon, copied attributes override previously copied attributes. The following stylesheet gives the desired result:
<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>
regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) Vincit omnia simplicitas Keep it simple
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Need to override previously c, Taco Fleur | Thread | RE: [xsl] Need to override previous, Michael Kay |
RE: [xsl] error in XSL file when us, Rahil Qamar | Date | RE: [xsl] Need to override previous, Michael Kay |
Month |