Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Convert xml file to plain text file

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 6/14/2007 3:03:00 PM

Hans wrote:

> I actually found my problem and that was that in the xml file (which I don't 
> generate myself) on the root element <HEADER> they have added two namespace 
> xmlns attributes that I actually omitted when I pasted the xml in my 
> question. When I removed one of them it worked. Not sure why the file become 
> empty because of that but maybe you understand why that happens?

Then you have hit the super FAQ in terms of XSLT 1.0 and XPath 1.0 which 
is how to select/match elements in a namespace. If you use e.g.
   HEADER/ROWS/ROW
then that selects elements of those names in _no_ namespace. If the 
input XML has elements in a namespace then for XSLT/XPath to 
select/match those elements you need to bind a prefix to the namespace 
URI so assuming you have

<HEADER xmlns="http://example.com/ns1">
<ROWS>
<ROW>
<TEXT>TEST row1</TEXT>
</ROW>
<ROW>
<TEXT>TEST row 2</TEXT>
</ROW>
<ROW>
<TEXT>TEST row 3</TEXT>
</ROW>
</ROWS>
</HEADER>

then in the stylesheet you need e.g.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:pf="http://example.com/ns1">
<xsl:output method="text" />
<xsl:template match="/">
     <xsl:apply-templates  select="pf:HEADER/pf:ROWS/pf:ROW"/>
</xsl:template>

<xsl:template match="pf:HEADER/pf:ROWS/pf:ROW">
     <xsl:value-of select="pf:TEXT" />
</xsl:template>

</xsl:stylesheet>


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent