Re: [xsl] Adding prefix to elements when I import a XML file

Subject: Re: [xsl] Adding prefix to elements when I import a XML file
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Wed, 31 Oct 2007 10:00:13 +0000
On 31/10/2007, La RKO <la_rko@xxxxxxxx> wrote:
> Suppose that I want to import a xml file into another
> file.
> The file that I want to import is like:
> <document>
> <head>this is a headline</head>
> <text>this is the text</text>
> <caption>this is the caption</caption>
> </document>
> to do that I use copy-of-select=document(file.xml)...
> and it works fine.
> But I want at the same time to add a prefix to some of
> the tags of the imported file, in order to have a
> output like:
> <document>
> <xed:head>this is a headline</xed:head>
> <xed:text>this is the text</xed:text>
> <xed:caption>this is the caption</xed:caption>
> </document>
> My question is how can I do that? Import and
> transforming at the same time?

Use a mode with the identity template and a specific template for the
elements you want to add the prefixes to, eg:

<xsl:apply-templates select="document('file.xml')" mode="addPrefix"/>


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

<xsl:template match="head|text|caption" mode="addNamespace">
  <xsl:element name="xed:{local-name()}" namespace="whatever_the_namespace_is">
    <xsl:apply-templates select="@|node()" mode="addNamespace"/>

Andrew Welch

Current Thread