| Author |
Append namespace with XSL
|
|
| Paul Yaroshenko 2006-06-27, 8:28 pm |
| Someone knows how to append namespace using XSL transformation?
For example, I have XML:
<AAA>
<BBB>
<CCC/>
</BBB>
</AAA>
How I can transform it to this from:
<NS:AAA>
<NS:BBB>
<NS:CCC/>
</NS:BBB>
</NS:AAA>
It looks very trivial fro the first sight but actually I'm unable to
complete this task.
----------------------------------------------------------------------
SamePaul
| |
| LighthouseRedSKY 2006-06-27, 8:28 pm |
| You can do this by using XSD.
As a first step you will create a xsd document.
This xsd document will be your namespace.
In your XML document you will add the this xsd document as a namespace with
NS prefix
(i wrote a "prefix" but maybe this description is called with different
definition).
As a result you can define your XML elements with NS.
For more information w3schools.com is very perfect site to learn.
"Paul Yaroshenko" <samepaul@postmark.net> wrote in message
news:O07kTQxlGHA.492@TK2MSFTNGP05.phx.gbl...
> Someone knows how to append namespace using XSL transformation?
>
> For example, I have XML:
>
> <AAA>
> <BBB>
> <CCC/>
> </BBB>
> </AAA>
>
> How I can transform it to this from:
>
> <NS:AAA>
> <NS:BBB>
> <NS:CCC/>
> </NS:BBB>
> </NS:AAA>
>
>
> It looks very trivial fro the first sight but actually I'm unable to
> complete this task.
> ----------------------------------------------------------------------
> SamePaul
| |
| Joe Fawcett 2006-06-27, 8:28 pm |
| You could use a modified version of the identity template:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://myDomain.com/namespaces/1">
<xsl:template match="node()|@*">
<xsl:choose>
<xsl:when test="local-name() = ''">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:element name="ns:{local-name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
--
Joe Fawcett - XML MVP
http://joe.fawcett.name
"Paul Yaroshenko" <samepaul@postmark.net> wrote in message
news:O07kTQxlGHA.492@TK2MSFTNGP05.phx.gbl...
> Someone knows how to append namespace using XSL transformation?
>
> For example, I have XML:
>
> <AAA>
> <BBB>
> <CCC/>
> </BBB>
> </AAA>
>
> How I can transform it to this from:
>
> <NS:AAA>
> <NS:BBB>
> <NS:CCC/>
> </NS:BBB>
> </NS:AAA>
>
>
> It looks very trivial fro the first sight but actually I'm unable to
> complete this task.
> ----------------------------------------------------------------------
> SamePaul
| |
| Paul Yaroshenko 2006-06-27, 8:28 pm |
| Just excellent... Thank you!
Joe Fawcett wrote:
> You could use a modified version of the identity template:
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:ns="http://myDomain.com/namespaces/1">
> <xsl:template match="node()|@*">
> <xsl:choose>
> <xsl:when test="local-name() = ''">
> <xsl:copy>
> <xsl:apply-templates select="node()|@*"/>
> </xsl:copy>
> </xsl:when>
> <xsl:otherwise>
> <xsl:element name="ns:{local-name()}">
> <xsl:apply-templates select="node()|@*"/>
> </xsl:element>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
> </xsl:stylesheet>
>
>
| |
| Joe Fawcett 2006-06-27, 8:28 pm |
| "Paul Yaroshenko" <samepaul@postmark.net> wrote in message
news:eFYTjx4lGHA.3352@TK2MSFTNGP02.phx.gbl...
> Just excellent... Thank you!
>
Just thinking more about your problem...
The example you showed had no attributes, if it did do you want them in a
namespace or not?
If so then use the example I posted, if not use this version:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://myDomain.com/namespaces/1">
<xsl:template match="node()">
<xsl:choose>
<xsl:when test="local-name() = ''">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:element name="ns:{local-name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="@*">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
--
Joe Fawcett - XML MVP
http://joe.fawcett.name
| |
| Paul Yaroshenko 2006-06-27, 8:28 pm |
| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Yes, I encountered problem with attributes, but this is kind of problem
I'm able to solve by myself :)<br>
I didn't know about 'local-name()' and that you can call function
inside of strings just by enclosing it by {}<br>
<br>
Joe Fawcett wrote:
<blockquote cite="mid%23jHlx56lGHA.2296@TK2MSFTNGP04.phx.gbl"
type="cite">
<pre wrap="">"Paul Yaroshenko" <a class="moz-txt-link-rfc2396E" href="mailto:samepaul@postmark.net"><samepaul@postmark.net></a> wrote in message
<a class="moz-txt-link-freetext" href="news:eFYTjx4lGHA.3352@TK2MSFTNGP02.phx.gbl">news:eFYTjx4lGHA.3352@TK2MSFTNGP02.phx.gbl</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Just excellent... Thank you!
</pre>
</blockquote>
<pre wrap=""><!---->Just thinking more about your problem...
The example you showed had no attributes, if it did do you want them in a
namespace or not?
If so then use the example I posted, if not use this version:
<xsl:stylesheet version="1.0"
xmlns:xsl=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/1999/XSL/Transform">"http://www.w3.org/1999/XSL/Transform"</a>
xmlns:ns=<a class="moz-txt-link-rfc2396E" href="http://myDomain.com/namespaces/1">"http://myDomain.com/namespaces/1"</a>>
<xsl:template match="node()">
<xsl:choose>
<xsl:when test="local-name() = ''">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:element name="ns:{local-name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="@*">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
</pre>
</blockquote>
<br>
</body>
</html>
|
|
|
|
| Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |