enos Posted July 7, 2009 Share Posted July 7, 2009 Hi everybody,that's my first post here.i have a problem with the namespaces using xslt to transform an xml document.The xml document is: <?xml-stylesheet href="dettagli.xsl" type="text/xsl"?><page> <compositore> <nome>Pink Floyd</nome> <recensione> bla bla bla </recensione> </compositore> <items xmlns="urn:apis:Components"> <Item> <Title>item1</Title> </Item> <Item> <Title>item2</Title> </Item> <Item> <Title>item3</Title> </Item> </items></page> The xslt section that doesn't work is: <div id="news"> <xsl:for-each select="/page/items/Item"> <p><xsl:value-of select="Title"/></p> </xsl:for-each> </div> I suppose that the xslt doesn't work because of the xmlns in the "items" node.Could you please suggest me how to fix that problem?Thank you. Link to comment Share on other sites More sharing options...
boen_robot Posted July 7, 2009 Share Posted July 7, 2009 Declare a prefix in the XSLT with the same namespace URI, and then use that prefix in the XPath statements, wherever the element you want to select has the same namespace URI.i.e. <xsl:stylesheet ... xmlns:api="urn:apis:Components" exclude-result-prefixes="api">... <div id="news"> <xsl:for-each select="/page/api:items/api:Item"> <p><xsl:value-of select="api:Title"/></p> </xsl:for-each> </div> Link to comment Share on other sites More sharing options...
enos Posted July 7, 2009 Author Share Posted July 7, 2009 You're very kind, it works perfectly! Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.