Problem using namespace within XSLT

admin

Administrator
Staff member
Hi community!

I am facing a problem using namespace within a XSL stylsheet. Let me describe my problem:

I am using the SAP XMLFormsBuilder within the SAP EnterprisePortal in order to provide a HTML based form for creating and editing specific XML documents. The data in the generated documents is finally presented as HTML using XSL Transformation.

In the XMLFormsBuilder you define the Schema of the XML document and the HTML GUI of the form. The Schema document looks like below (extract):

<?xml version="1.0" encoding="utf-8"?>
<schema targetNamespace="http://www.xmlspy.com/schemas/orgchart"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xyz="http://www.xmlspy.com/schemas/orgchart" Version="6.3.0">
<element name="commodity"
default=""
minOccurs="1"
maxOccurs="1"
ns="p2p"
xmlns:p2p="http://www.portal.p2p.com">
<complexType>
<sequence>
<element name="administrative_information"
default=""
minOccurs="1"
maxOccurs="1"
ns="p2p">
<complexType>
<sequence>
<element name="creation_date"
default=""
minOccurs="1"
maxOccurs="1"
type="date"
ns="p2p"/>
...

As far as I understand, each element defined in the Schama belongs to the namespace "p2p" and this is exactly what I want.

The XML document generated by the form looks like below (extract):

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href=http://www.webdeveloper.com/forum/archive/index.php/"show_card.xsl"?>

<commodity xmlns:xf="http://www.sapportals.com/wcm/app/xmlforms"
xmlns:xsi="http//www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="/etc/xmlforms/P2PCategoryCard_TEST/P2PCategoryCard_TEST-Schema.xml">

<administrative_information>
<creation_date>2005-07-04</creation_date>
...

Consequently, the file "show_card.xsl" is the responsible XSLT stylesheet, which looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:p2p="http://www.portal.p2p.com">

<xsl:output method="html"/>

<xsl:template match="p2p:commodity">

<html>
<body>
<h2>XSLT Test</h2>
Creation Date: <xsl:value-of select="p2p:administrative_information/p2p:creation_date"/>
</body>
</html>

</xsl:template>
</xsl:stylesheet>

The problem in the XSLT stylesheet is, that I want to access the XML document elements using their namespace. And this is exactly what does not work for me. On the other hand, if I remove the reference to the namespace:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:p2p="http://www.portal.p2p.com">

<xsl:output method="html"/>

<xsl:template match="commodity">

<html>
<body>
<h2>XSLT Test</h2>
Creation Date: <xsl:value-of select="administrative_information/creation_date"/>
</body>
</html>

</xsl:template>
</xsl:stylesheet>

the stylesheet works fine, but for some technical reasons, which I don't want to explain here, I have to use the namespace when accessing the XML document elements.

For technical reasons, I cannot change the format of the Schema document and also cannot change the format of the generated XML document. The only file I can change and control is the XSLT stylsheet.

My question is now, in the case described above, if there is any way to use the namespace in the sytlesheet when accessing the XML elements?

Any help is appreciated.

Cheers,

Adam Kreuschner
 
Back
Top