[DDI-SRG] Trouble using XSLT with 3_0_CR

I-Lin Kuo ikuoikuo at gmail.com
Mon Aug 13 14:16:18 EDT 2007


Hi Matt,

It's the drawback of using namespaces....

<xsl:template match="DDIInstance"> and <xsl:template match="/DDIInstance">
will fail because the original element <DDIInstance
xmlns="ddi:instance:3_0_CR" ...> has a namespace of "ddi:instance:3_0_CR"

<xsl:template match="/"> should fail whether or not namespaces are involved,
as that only matches the root but not the root element. Sometimes it will
work because the underlying default matching compensates.

<xsl:template match="/*"> will work

Using namespaces means that a lot of your matching templates will have to
look like
  <xsl:template match="ddii:DDIInstance" xmlns:ddii="ddi:instance:3_0_CR">
where you have to match the namespace (you don't have to match the namespace
prefix, though) as well as the element name.


On 8/13/07, Matthew Richardson <matvey at isr.umich.edu> wrote:
>
> I'm having a bit of trouble writing XSLT that works with the latest
> instance
> schema. For some reason, I can't get Cocoon to recognize the root element
> of
> the file. I'm hoping this is something *I'm* doing in my XSLT, as opposed
> to
> something with the schema. I used similar code on the pervious DDI3
> version,
> and had no problems.
>
> Here's the URL:
>
> http://staging.icpsr.umich.edu/cocoon/DSDR/CDG/chart.xml
>
> Cocoon is following this pipeline:
>
> <map:pipeline>
> <map:match pattern="chart.xml">
>     <map:generate src="xml/DDI3/04402v3.xml"/>
>     <map:transform src="xslt/svgprep000.xsl" />
>     <map:serialize type="xml"/>
> </map:match>
> </map:pipeline>
>
> When it sees chart.xml it reads 04402v3.xml, which is just a snippet of
> XML,
> really:
>
> <?xml version="1.0" encoding="us-ascii"?>
> <DDIInstance xmlns="ddi:instance:3_0_CR"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xsi:schemaLocation="ddi:instance:3_0_CR
> http://staging.icpsr.umich.edu/DDI/xsd/instance.xsd">
>     <MaintainableID xmlns="ddi:reusable:3_0_CR">
>         <ID>ICPSR_4402</ID>
>     </MaintainableID>
> </DDIInstance>
>
> I validated the XML; no problem there. The XSLT that renders it looks like
> this:
>
> <?xml version="1.0" encoding="us-ascii"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:template match="/">
> <test>
>     element: <xsl:value-of select="name()" />
> </test>
> </xsl:template>
> </xsl:stylesheet>
>
> It's just supposed to display one element...test...and the name of the
> root
> element. I'm doing this for testing, because I can't seem to snag the root
> element. Normally I do the first match thusly:
>
> <xsl:template match="DDIInstance">
>
> But that finds no match. Even though there's clearly a DDIInstance element
> in the XML file.
>
> <xsl:template match="/DDIInstance">
>
> Also fails.
>
> <xsl:template match="/">
>
> Works, but it still doesn't see DDIInstance as the root element. I'm very
> confused why the method I've been using for DDI2 and previous DDI3 version
> suddenly fails.
>
> Am I missing something obvious? I checked for issues of character
> encoding,
> typos, and mac page breaks...I can't figure out what's changed.
>
> Matthew
>
> _______________________________________________
> DDI-SRG mailing list
> DDI-SRG at icpsr.umich.edu
> http://www.icpsr.umich.edu/mailman/listinfo/ddi-srg
>



-- 
I-Lin Kuo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.icpsr.umich.edu/pipermail/ddi-srg/attachments/20070813/bc28a180/attachment.html 


More information about the DDI-SRG mailing list