Subject: Re: [xsl] Namespace issue when running a Xalan transform through Java From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Fri, 27 Aug 2010 19:36:41 +0200 |
The extra namespace declarations all appear in elements that are in a different namespace in the source, but which need to end up in the namespace www.logica.com/project and are transformed by the following extract of a stylesheet:
<xsl:template match="*" mode="copy"> <xsl:variable name="element-name" select="local-name()"></xsl:variable> <xsl:choose> <xsl:when test="contains($element-name, 'List')"> <xsl:call-template name="process-lists"></xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:element name="{local-name()}" namespace="http://www.logica.com/project"> <xsl:apply-templates mode="copy"></xsl:apply-templates> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template name="process-lists"> <xsl:variable name="element-name" select="local-name()"></xsl:variable> <xsl:element name="{$element-name}" namespace="http://www.logica.com/pnd"><xsl:value-of select="./dip:N"/></xsl:element> <xsl:variable name="local-element-val"><xsl:value-of select="$element-name"/><xsl:text>LocalVal</xsl:text></xsl:variable> <xsl:element name="{$local-element-val}" namespace="http://www.logica.com/project"><xsl:value-of select="./dip:NP"/></xsl:element> </xsl:template>
The namespace addition to the <xsl:element> processing is not reproduced by XSLTProc or Xalan via the command line, only in the default javax implementation.
<root xmlns="http://example.com/dip"> <foo><bar>baz</bar></foo> <ListExample> <N>N1</N> <NP>NP1</NP> </ListExample> <ListExample> <N>N2</N> <NP>NP2</NP> </ListExample> <ListExample> <N>N3</N> <NP>NP3</NP> </ListExample> </root>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dip="http://example.com/dip" xmlns="http://www.logica.com/project" version="1.0">
<xsl:template match="/"> <xsl:apply-templates mode="copy"/> </xsl:template>
<xsl:template match="*" mode="copy"> <xsl:variable name="element-name" select="local-name()"></xsl:variable> <xsl:choose> <xsl:when test="contains($element-name, 'List')"> <xsl:call-template name="process-lists"></xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:element name="{local-name()}" > <xsl:apply-templates mode="copy"></xsl:apply-templates> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template name="process-lists"> <xsl:variable name="element-name" select="local-name()"></xsl:variable> <xsl:element name="{$element-name}" namespace="http://www.logica.com/pnd"><xsl:value-of select="./dip:N"/></xsl:element> <xsl:variable name="local-element-val"><xsl:value-of select="$element-name"/><xsl:text>LocalVal</xsl:text></xsl:variable> <xsl:element name="{$local-element-val}"><xsl:value-of select="./dip:NP"/></xsl:element> </xsl:template>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dip="http://example.com/dip" xmlns="http://www.logica.com/project" xmlns:pnd="http://www.logica.com/pnd" version="1.0">
<xsl:template match="/"> <xsl:apply-templates mode="copy"/> </xsl:template>
<xsl:template match="*" mode="copy"> <xsl:variable name="element-name" select="local-name()"></xsl:variable> <xsl:choose> <xsl:when test="contains($element-name, 'List')"> <xsl:call-template name="process-lists"></xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:element name="{local-name()}" > <xsl:apply-templates mode="copy"></xsl:apply-templates> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template name="process-lists"> <xsl:variable name="element-name" select="local-name()"></xsl:variable> <xsl:element name="pnd:{$element-name}"><xsl:value-of select="./dip:N"/></xsl:element> <xsl:variable name="local-element-val"><xsl:value-of select="$element-name"/><xsl:text>LocalVal</xsl:text></xsl:variable> <xsl:element name="{$local-element-val}"><xsl:value-of select="./dip:NP"/></xsl:element> </xsl:template>
Martin Honnen http://msmvps.com/blogs/martin_honnen/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Namespace issue when runn, Etheridge, Stephen | Thread | RE: [xsl] Namespace issue when runn, Etheridge, Stephen |
Re: [xsl] Help on node selection, Lars Huttar | Date | Re: [xsl] Catalog support in Saxon-, Evan Leibovitch |
Month |