Jump to content

Namespace Problem


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>

Edited by boen_robot
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...