Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - namespace prefixes in output xml

 
Thread Tools Search this Thread
Old 05-25-2006, 08:59 AM   #1
Default namespace prefixes in output xml


Hi,

I would like to generate XML (struts code) from XML with XSL
transformation. I run into problem when I wanted to use tags with
prefixes, like <html:text />.

I included namespace specification to the header:
<xsl:stylesheet version='1.0'
xmlnssl='http://www.w3.org/1999/XSL/Transform' xmlns:html="struts">

It works, but it also includes namespace information in every tag,
that's not perfect:

<html:text xmlns:html="struts">
ez a teszt
</html:text>

So how can I use the prefixes without the additional namespace
information in the output tags?

Thanks,

Hubidubi



Hubidubi
  Reply With Quote
Old 05-25-2006, 03:39 PM   #2
George Bina
 
Posts: n/a
Default Re: namespace prefixes in output xml

Hi,

You can simply iterate on the ancestor or self axes and output the
XPath expressin matching the current element. Below you can find a
sample stylesheet that outputs the XPath expressions matching all the
document nodes.

<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput indent="yes"/>

<xsl:template match="/">
<xpaths>
<xsl:apply-templates/>
</xpaths>
</xsl:template>
<xsl:template match="*">
<xpath>
<xsl:for-each select="ancestor-or-self::*">
<xsl:value-of select="name()"/>
<xsl:variable name="count">
<xsl:number/>
</xsl:variable>
<xsl:text>[</xsl:text>
<xsl:value-of select="$count"/>
<xsl:text>]</xsl:text>
<xsl:if test="position()!=last()">/</xsl:if>
</xsl:for-each>
</xpath>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>

On something like

<?xml version="1.0" encoding="UTF-8"?>
<test>
<a> </a>
<b/>
<a>
<c> </c>
<x> </x>
</a>
</test>


it will give you
<?xml version="1.0" encoding="UTF-8"?>
<xpaths>
<xpath>test[1]</xpath>
<xpath>test[1]/a[1]</xpath>
<xpath>test[1]/b[1]</xpath>
<xpath>test[1]/a[2]</xpath>
<xpath>test[1]/a[2]/c[1]</xpath>
<xpath>test[1]/a[2]/x[1]</xpath>
</xpaths>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump