RE: [xsl] Copying an entire NodeSet with modified selected attribute values

Subject: RE: [xsl] Copying an entire NodeSet with modified selected attribute values
From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx>
Date: Thu, 23 Jun 2005 16:33:52 +0100
> Given SVG:
>
> <svg width="100%" height="100%" viewBox="-24 -21 1296 1135"
> preserveAspectRatio="xMinYMin meet" kerning="0"
> xml:space="preserve"
> xmlns:xlink="http://www.w3.org/1999/xlink"; style="stroke:
> black; fill: none;">
> 	<g id="122" type="443" node="Yes">
> 	...
> 	</g>
> </svg>
>
> I would like to keep/copy the entire SVG Structure, but just
> change specific attribute values.
>
> Example :clone it, except that : (...) height="NEWVALUE" (...)
>
> Could it be possible to simple use xsl:copy-of function with
> exceptions (IFs)?

You could use:

<xsl:template match="svg">
  <xsl:copy>
    <xsl:copy-of select="@*[not(local-name() = 'height')]"/>
    <xsl:attribute name="height">NEWVALUE</xsl:attribute>
    <xsl:copy-of select="*"/>
  </xsl:copy>
</xsl:template>

Which copies the element, all it's attributes apart from 'height',
creates a new height attribute with a value of 'NEWVALUE', and then
copies all it's children.  Maybe use apply-templates there instead of
copy-of select if it's used as part of an identity transform.

Cheers
andrew

Current Thread