namespace in root

Here should go questions about transforming XML with XSLT and FOP.
JennMarie
Posts: 1
Joined: Fri May 03, 2013 11:05 pm

namespace in root

Post by JennMarie »

I am really new to xslt. I am trying to transform a xml file using xslt 2.0 in oxygen using the Saxon-EE 9.4.0.6 transformer.

Here's the xml:
<?xml version='1.0' encoding='ISO-8859-1'?>
<?xml-stylesheet href='../codebook2-0.xsl' type='text/xsl'?>
<codeBook xmlns="http://www.icpsr.umich.edu/DDI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.icpsr.umich.edu/DDI http://www.icpsr.umich.edu/DDI/Version1-3.xsd">
<docDscr source="archive">
<citation>
<titlStmt source="archive">
<titl source="archive">Work Trends Poll: Laid Off--American Workers and Employers Assess a Volatile Labor Market</titl>
</titlStmt>
<holdings URI="http://www.ropercenter.uconn.edu/cgi-bi ... RKTRENDS14"/>
</citation>
</docDscr>
</codeBook>

When I apply this sample stylesheet:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>Title of study</h2>
<h1><xsl:value-of select="codeBook/docDscr/citation/titlStmt/titl"/></h1>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

The only result is my text that I put in h2 or Title of Study.

If I remove the xmlns="http://www.icpsr.umich.edu/DDI" from the root <codeBook>, then this stylesheet works fine.

I'm just wondering if someone can explain why removing this xmlns declaration from the root <codeBook> would have that effect.

Thanks for the help.
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: namespace in root

Post by george »

The name tests in the XPath expression select those elements from no namespace. As your elements are in the http://www.icpsr.umich.edu/DDI namespace they are not selected. When you remove the namespace declaration on the XML element then the XPath expression selects them. To select the elements in that namespace there are two possibilities:

1. Add

Code: Select all


xpath-default-namespace="http://www.icpsr.umich.edu/DDI"
on the xsl:stylesheet element

2. Add a namespace declaration for your namespace like

Code: Select all


xmlns:ddi="http://www.icpsr.umich.edu/DDI"
and then use that prefix for each name test in the XPath expression:

Code: Select all


<xsl:value-of select="ddi:codeBook/ddi:docDscr/ddi:citation/ddi:titlStmt/ddi:titl"/>
Best Regards,
George
George Cristian Bina
Post Reply