xsl-list
[Top] [All Lists]

RE: Adding Prefixes to Elements

2005-03-07 09:17:27

In XMLSpy, how would I go about automatically adding
prefixes to every element name in my XSL stylesheet.
For example, when I have a template match="A/B/C", I
would like it to change to x:A/x:B/x:C.

Any suggestions?
<<<

Jonathan, if XMLSpy doesn't offer this feature and you don't find an editor that does, perhaps it wouldn't be too difficult to write an XSL transform to accomplish this?

From Sal Mangano's "XSLT Cookbook", the following is what he calls an
"identity transform"--one that simply copies input to output.


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="node(  ) | @*">
 <xsl:copy>
   <xsl:apply-templates select="@* | node(  )"/>
 </xsl:copy>
</xsl:template>

</xsl:stylesheet>

The idea, then, is to augment this with templates to transform what you want. For example, to [naively] prefix all "select" attributes with "x:", you could add the following template:

<xsl:template match="@*[local-name() = 'select']">
   <xsl:attribute name="select">
   <xsl:value-of select="concat('x:', .)"/>
   </xsl:attribute>
</xsl:template>

Of course a realistic template would need to do more processing such as splitting at "/" separators, recombining, etc.

Regards,

--A

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar ? get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>