![]() |
|
|
|||||||
![]() |
XML - namespace prefixes in output xml |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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' xmlns 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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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" xmlns <xsl <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 |
|