473,385 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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'
xmlns:xsl='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

May 25 '06 #1
1 1307
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="http://www.w3.org/1999/XSL/Transform">
<xsl:output 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

May 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Chris Spencer | last post by:
Does anyone know how to make ElementTree preserve namespace prefixes in parsed xml files? The default behavior is to strip a document of all prefixes and then replace them autogenerated prefixes...
20
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"...
3
by: Mike Dickens | last post by:
hi, i'm sure this has come up before but havn't managed to find an answer. if i have the following xslt <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet method="xml" version="1.0"...
5
by: Adam Barr | last post by:
I have a tag foo that I want to copy unchanged when it is a subtag of bar, so I have a template (x is the namespace for the document): <xsl:template match="x:bar/x:foo"> <xsl:copy>...
4
by: Hollywood | last post by:
I'm using XML serialization to produce the following XML document: <TestDoc xmlns:srd="some-url"> <Additional> <Security> <srd:Login>login_id</srd:Login> <srd:Password>password</srd:Password>...
4
by: jb | last post by:
I have discovered that when the WSDL is auto-generated in .NET (i.e. http://.../MyService.asmx?WSDL): * Prior to SP1, it generated xmlns:s0="http://mynamespace/" in <wsdl:definitions>, and then...
2
by: steve | last post by:
Can someone point me to some information on namespace best practices? Questions I have are as follows: 1) Should I use .NET namespaces or URL, URI and URN's? Ie mycompany.mydivision.myapp vs...
4
by: Samuel R. Neff | last post by:
I'm writing an xslt in vs.net 2003 and in order to get intellisense on the html content I added the default namespace declaration xmlns="http://schemas.microsoft.com/intellisense/ie5". However,...
5
by: johanneskrueger | last post by:
Hello, I'm currently using <xsl:copy-of select="document(...)/svg:svg"/to embed an SVG file into an XHTML file. I already defined the SVG namespace and assigned svg as its prefix in my XSLT 1.0...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.