trying to sort something out...
XSLT (through XPath, I guess (http://www.w3.org/TR/xpath#function-id) has an id() function that, if
I understand the docs correctly, will return the node (or nodeset, if the parameter is a nodeset of
id strings) from the document that has the given id value.
Great!
Now, one problem. For that to work, apparently the id value needs to be declared as an attribute of
ID type in a DTD. Bummer. See note in http://www.w3.org/TR/xslt#section-Embedding-Stylesheets.
Ok, so I tried that, but Oxygen doesn't seem to find it.
Does Oxygen (and/or XSLT in general, to your knowledge) support the id() function in XSLT? Can it
work with an ID-typed element?
My problem is that I am presented with an XML document that makes heavy use of IDREF type elements
and I'm trying to transform them in XSLT. Perhaps there's a better way or I'm doing something
wrong. Will post to xml dev list if this comes back negative.
attached are my (hackish! just trying stuff out) xml, xsd, and xsl files I've been using to test.
Note that in the xsl
<xsl:variable name="onode" select="id(oid)"/>
ids:<xsl:value-of select="$onode"/>
"onode" is null (well, empty nodeset.)
Thanks,
Linus
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE DocRoot
[
<!ELEMENT DocRoot ANY >
<!ATTLIST DocRoot
xmlns:xsi CDATA #IMPLIED
xsi:noNamespaceSchemaLocation CDATA #IMPLIED >
<!ELEMENT Event ( id, OriginRef ) >
<!ELEMENT id (#PCDATA) >
<!ELEMENT OriginRef (#PCDATA) >
<!ELEMENT Latitude (#PCDATA) >
<!ELEMENT Longitude (#PCDATA) >
<!ELEMENT Location (Latitude, Longitude)>
<!ELEMENT Origin (Location) >
<!ATTLIST Origin
id ID #REQUIRED >
]>
<DocRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file:/Users/linus/workspace/xml-scratch/schema1.xsd">
<Event>
<id>nc122604a</id>
<OriginRef>www.iris.edu_cmt_o122604a</OriginRef>
</Event>
<Origin id="www.iris.edu_cmt_o122604a">
<Location>
<Latitude>42</Latitude>
<Longitude>-36</Longitude>
</Location>
</Origin>
</DocRoot>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="DocRoot" type="RootType"/>
<xs:complexType name="RootType">
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="Event" type="EventType"/>
<xs:element name="Origin" type="OriginType"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="EventType">
<xs:sequence>
<xs:element name="id" type="xs:ID"/>
<xs:element name="OriginRef" type="xs:IDREF"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="OriginType">
<xs:sequence>
<xs:element name="Location" type="GeoLocation"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
<xs:complexType name="GeoLocation">
<xs:sequence>
<xs:element name="Latitude" type="xs:float"/>
<xs:element name="Longitude" type="xs:float"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="DocRoot">
Document Root
<xsl:variable name="oid" select="Event/OriginRef"/>
oid:<xsl:value-of select="$oid"/>
<xsl:variable name="onodes" select="//Origin"/>
ns:<xsl:value-of select="$onodes"/>
<xsl:variable name="onode" select="id(oid)"/>
ids:<xsl:value-of select="$onode"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Event">
<xsl:text>Event </xsl:text>
id=<xsl:value-of select="id"/>,
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="OriginRef">
<xsl:text>Origin Ref = </xsl:text>
<xsl:variable name="oref" select="string(node())"/>
<xsl:value-of select="$oref"/>
<xsl:call-template name="originTemplate">
<xsl:with-param name="origin" select="id($oref)"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="originTemplate">
<xsl:param name="origin"/>
oTemplate
<xsl:value-of select="$origin"/>
</xsl:template>
<xsl:template match="node()"/>
</xsl:stylesheet>
_______________________________________________
oXygen-user mailing list
[email protected]
http://www.oxygenxml.com/mailman/listinfo/oxygen-user