Jump to content

Namespace Problem


enos

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...