Newbie: XML 2 XML and namespaces

M

Mark Smits

Hi, newbie needs help...

My from XML has a namespace defined with no prefix. I tried to create a XSL
that converts this from XML to another one. I tried it without that
namespace and with that namespace. No matter what I try, I can't get this to
work.

The only time I succeed is when deleting the namespace in the from XML file.
But that's no option...

Inserted below are a sample XML and XSL file and both have the name spaces.
Can someone please point me in the right direction: how to get the XSL to
work with that namespace declaration in the XML.

Thanks,
Mark

=============================================
XML
=============================================
<?xml version="1.0" encoding="UTF-8" ?>
<Report xmlns="urn:crystal-reports:schemas"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="urn:crystal-reports:schemas Untitled.xsd" >
<Details_1 SectionNumber="0">
<Klanten.Klantnummer
FieldName="{Klanten.Klantnummer}">ALFKI</Klanten.Klantnummer>
<Klanten.Bedrijf FieldName="{Klanten.Bedrijf}">Alfreds
Futterkiste</Klanten.Bedrijf>
<Klanten.Contactpersoon FieldName="{Klanten.Contactpersoon}">Maria
Anders</Klanten.Contactpersoon>
<Klanten.Functie
FieldName="{Klanten.Functie}">Vertegenwoordiger</Klanten.Functie>
<Klanten.Adres FieldName="{Klanten.Adres}">Obere Str. 57</Klanten.Adres>
<Klanten.Plaats FieldName="{Klanten.Plaats}">Berlijn</Klanten.Plaats>
<Klanten.Provincie FieldName="{Klanten.Provincie}"></Klanten.Provincie>
<Klanten.Postcode FieldName="{Klanten.Postcode}">12209</Klanten.Postcode>
<Klanten.Land FieldName="{Klanten.Land}">Duitsland</Klanten.Land>
<Klanten.Telefoonnummer
FieldName="{Klanten.Telefoonnummer}">030-0074321</Klanten.Telefoonnummer>
<Klanten.Faxnummer
FieldName="{Klanten.Faxnummer}">030-0076545</Klanten.Faxnummer>
</Details_1>
</Report>
=============================================
XSL
=============================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns="urn:crystal-reports:schemas"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:eek:utput method="xml"/>
<xsl:template match="/">
<xsl:apply-templates select="/Report/Details_1"></xsl:apply-templates>
</xsl:template>
<xsl:template match="Details_1">
<xsl:value-of select="Klanten.Klantnummer"/>
</xsl:template>
</xsl:stylesheet>
 
P

Patrick TJ McPhee

% My from XML has a namespace defined with no prefix.

This doesn't mean the corresponding tags in XSL need have no prefix.

[...]

% <xsl:stylesheet version="1.0"
% xmlns="urn:crystal-reports:schemas"
Try

xmlns:cr="urn:crystal-reports:schemas"

[...]

% <xsl:apply-templates select="/Report/Details_1"></xsl:apply-templates>
Try
<xsl:apply-templates select="/cr:Report/cr:Details_1"></xsl:apply-templates>

% <xsl:template match="Details_1">
% <xsl:value-of select="Klanten.Klantnummer"/>
and

<xsl:template match="cr:Details_1">
<xsl:value-of select="cr:Klanten.Klantnummer"/>
 
M

Mark Smits

Thx, that worked perfectly :)

Patrick TJ McPhee said:
% My from XML has a namespace defined with no prefix.

This doesn't mean the corresponding tags in XSL need have no prefix.

[...]

% <xsl:stylesheet version="1.0"
% xmlns="urn:crystal-reports:schemas"
Try

xmlns:cr="urn:crystal-reports:schemas"

[...]

% <xsl:apply-templates select="/Report/Details_1"></xsl:apply-templates>
Try
<xsl:apply-templates
 

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top