473,791 Members | 3,179 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:styleshe et version='1.0'
xmlns:xsl='http ://www.w3.org/1999/XSL/Transform' xmlns:html="str uts">

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

<html:text xmlns:html="str uts">
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 1335
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:styleshe et 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="ancesto r-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
10103
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 like ns0, ns1, etc. The correct behavior should be to write the file in the form that it was read, which it seems to do correctly for everything except namespace prefixes. The docs mention "proper" output can be achieved by using the Qname object,...
20
6799
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" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
10043
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" xmlns:ns1="abc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" media-type="text/xml" standalone="yes" version="1.0"/> <xsl:template match="/">
5
5278
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> <xsl:apply-templates/> </xsl:copy> </xsl:template> BUT, I discovered that someone has been mis-speling foo as foop in the
4
2630
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> </Security> </Additional> </TestDoc>
4
4605
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 output my web methods as "s0:MyWebMethod" in <wsdl:message> sections * At SP1, it generates xmlns:tns="http://mynamespace/" in <wsdl:definitions>, and then output my web methods as "tns:MyWebMethod" in <wsdl:message> sections
2
3487
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 http://www.mycompany.com/division/app? 2) Should I use namespace prefixes? I thought I read something using prefixes is a bad idea? 3) etc. Thanks in advance.
4
7722
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, even though I also have exclude-result-prefixes="#default" declared the default namespace is still outputted on the resulting document. <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0"...
5
6963
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 sheet. What commands instead of copy-of could I use in order to get the prefix with every element from the external file, e.g. <svg:svg>, <svg:lineetc. instead of just <svgand <line>, as it is noted in the external file?
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10419
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.