Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Convert xml file to plain text file >Thread Next - Re: Convert xml file to plain text file Re: Convert xml file to plain text fileTo: 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/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
