Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL default namespace or what?

Status
Not open for further replies.

pvanhelvoirt

Technical User
Nov 27, 2009
1
NL
Hi to all,

I am relatively new to XSL and hope someone can help me.

Using a XSLT I need to transform one XML to another format.
For some reason I don't understand (yet) I can only "read" tags that have a namespace declaration. Tags with no namespace declaration give an empty result. I think there is something wrong in my declarations or in my XPath string. I have included a piece of the XML and my XSL, hopefully you can help me to figger out what I do wrong.

Thanks!
Pieter


XML sample:

[xml]
<EML xmlns="urn:eek:asis:names:tc:evs:schema:eml" xmlns:ns2="urn:eek:asis:names:tc:ciq:xsdschema:xAL:2.0"
xmlns:ns3="urn:eek:asis:names:tc:ciq:xsdschema:xNL:2.0"
xmlns:ns4=" xmlns:ns5="urn:eek:asis:names:tc:evs:schema:eml:ts"
xmlns:ns6=" xmlns:ns7=" xmlns:xsi=" Id="230b" SchemaVersion="5"
xsi:schemaLocation="urn:eek:asis:names:tc:evs:schema:eml 230-candidatelist-v5-0.xsd http://www.kiesraad.nl/extensions kiesraad-eml-extensions.xsd">
<TransactionId>1</TransactionId>
<IssueDate>2009-10-09</IssueDate>
<ns6:CreationDateTime>2009-10-09T10:00:02.046+02:00</ns6:CreationDateTime>
</EML>
[/xml]

XSL sample:

[xml]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=" xmlns="urn:eek:asis:names:tc:evs:schema:eml" xmlns:ns2="urn:eek:asis:names:tc:ciq:xsdschema:xAL:2.0"
xmlns:ns3="urn:eek:asis:names:tc:ciq:xsdschema:xNL:2.0"
xmlns:ns4=" xmlns:ns5="urn:eek:asis:names:tc:evs:schema:eml:ts"
xmlns:ns6=" xmlns:ns7=" xmlns:xsi=" version="1.0">
<xsl:template match="/">
<form>
<issueDate>
<xsl:value-of select="/EML/TransactionId"/>
</issueDate>
<creationDate>
<xsl:value-of select="//ns6:CreationDateTime[1]"/>
</creationDate>
</form>
</xsl:template>
</xsl:stylesheet>
[/xml]
 
[1] First you add a prefixed (ns1, say) namespace which corresponds to the default namespace of the original xml document (not the xsl doc even though incidently the same, but they are of completely different consideration) and put it in the xsl root.
[tt][ignore]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=" xmlns="urn:eek:asis:names:tc:evs:schema:eml"
[/ignore][blue]xmlns:ns1="[ignore]urn:eek:asis:names:tc:evs:schema:eml[/ignore]"[/blue][ignore]
xmlns:ns2="urn:eek:asis:names:tc:ciq:xsdschema:xAL:2.0"
xmlns:ns3="urn:eek:asis:names:tc:ciq:xsdschema:xNL:2.0"
xmlns:ns4=" xmlns:ns5="urn:eek:asis:names:tc:evs:schema:eml:ts"
xmlns:ns6=" xmlns:ns7=" xmlns:xsi=" version="1.0">
[/ignore][/tt]
[2] Then change the xpath making explicit reference to the ns1 (the default namespace of the original xml).
><xsl:value-of select="/EML/TransactionId"/>
[tt]<xsl:value-of select="/[red]ns1:[/red]EML/[red]ns1:[/red]TransactionId"/>[/tt]

[3] As a side note: make sure you understand the default namespace in the xsl document root. It means only that your form, issueDate, createDate are all defined in that namespace, nothing more. If they are really not so and that they belongs to empty namespace, then you have to take that line out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top