how to reference data when a node has a XMLNS pointing to a DTD?

A

Andy

OK, I'm not sure what I'm missing here.

I'm working with this XML:

<?xml version="1.0" encoding="utf-8"?>
<GroupDataBlock xmlns="http://www.acme.com/data.dtd">
<GroupInfo>
<ProgramID>3002616</ProgramID>
</GroupInfo>
</GroupDataBlock>

and this XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:value-of select="GroupDataBlock/GroupInfo/ProgramID" /><br />
</xsl:template>
</xsl:stylesheet>

Any idea why it won't show the ProgramID value?

Is there something in the DTD that I need to know to display this
correctly? Isn't the GroupInfo nested within the GroupDataBlock node?

Any help would be much appreciated.

Thanks,
Andy
 
D

David Carlisle

Namespace declarations in xmlns don't really "point to" anything, the
URI is just a string identifying the namespace, it is never "looked up"

This is a FAQ. (see the faq for xsl-list for example)

Andy said:
OK, I'm not sure what I'm missing here.

I'm working with this XML:

<?xml version="1.0" encoding="utf-8"?>
<GroupDataBlock xmlns="http://www.acme.com/data.dtd">

so that is the element with name consisting of local name
GroupDataBlock
and namespace
http://www.acme.com/data.dtd
(it's unusual to use a dtd uri as a namespace, but anything would do,
xmlns="data:,hello"
for example.) The Processor will not look at the dtd file anyway.

<xsl:value-of select="GroupDataBlock/GroupInfo/ProgramID" />

that selects an element GroupDataBlock in no-namespace (and similarly
GroupInfo and ProgramID

add xmlns:x="http://www.acme.com/data.dtd" to your xsl:stylesheet
element so x: is in scope for the whole stylesheet then you can use

<xsl:value-of select="x:GroupDataBlock/x:GroupInfo/x:programID" />

to select elements from this namespace.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top