Forum Moderators: open

Message Too Old, No Replies

Accessing schema annotation during XSLT

Is it possible?

         

john_k

9:24 pm on Mar 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The XML I am working on has many elements for which there is a corresponding restriction element in the schema. The restrictions all enumerate a list of possible numeric values. Each value has a corresponding annotation node that contains a documentation node.

The XML of course just has the numeric value. Is there some way that I can do a lookup during the XSL Transformation to get the corresponding annotation/documentation node? I would like to display the numeric value followed by the corresponding documentation text.

Hopefully that made sense. All help is appreciated!

john_k

10:26 pm on Mar 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay - it seems like I need to use the document() function, but I can't get that to work. This doesn't seem to work though. (It always returns an empty node set). Any ideas?

irnbru

2:56 pm on Mar 16, 2005 (gmt 0)

10+ Year Member



Rather than doing a lookup is not possible to use an absolute path to the element? Something like

document('foobar.xsd')/xsd:schema/xsd:simpleType[@name='<element anme>']/xsd:annotation

john_k

3:53 pm on Mar 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the reply irnbru. That is what I have tried. Here is the exact line from the xslt file:

<xsl:value-of select="document('ndex.xsd')/xsd:schema/xsd:simpleType[@name='AssociationCodePersonType']/xsd:restriction[@base='xsd:token']/xsd:enumeration[@value='1']/xsd:annotation/xsd:documentation"/>yyyy

This doesn't cause any errors, it just returns nothing, so only the yyyy is displayed. (the yyyy is in there just so I am certain that processing hits this line of the xsl file)

I am doing this from an .aspx file (ASP.Net). I am certain that I have used the document function with MS XML transformations in the past, so I don't think that is a contributing factor.

I should also mention that this is a server-side transformation, and is not being done on the client machine.

I am certain that the XPath to the node is correct, but if it will help, I can post or PM the schema.

irnbru

4:11 pm on Mar 16, 2005 (gmt 0)

10+ Year Member



If you can post minimal versions of each that would help.

john_k

5:28 pm on Mar 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay. The first section is a simplified version of the XSLT file. I have left in a few of the various protocol & path combinations I have tried to get to the schema file. I have also tried this with a simple XML file with the same results.

The second section is a simplified version of the schema file that I am trying to get at with the document() function. I have removed all but one simpleType. And from that remaining type, I have removed most of the enumeration nodes.

XSLT file:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:jxdd="http://www.it.ojp.gov/jxdm/3.0.2"
xmlns:ndex="http://www.ndex.gov/1.0.3"
xmlns:inc="http://caseincidentreport.com/1.0.3"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsl:output method="html" indent="yes" encoding="UTF-8"/>

<xsl:template match="inc:CaseIncidentReport">
<xsl:apply-templates select="inc:Incident"/>
</xsl:template>

<xsl:template match="inc:Incident">
***<xsl:value-of select="document('ndexTEST.xsd')/xsd:schema/xsd:simpleType[@name='AssociationCodePersonType']/xsd:restriction[@base='xsd:token']/xsd:enumeration[@value='1']/xsd:annotation/xsd:documentation"/>line 1<br/>
***<xsl:value-of select="document('//localhost/wsIBRClientSite/Styles/XSLT/ndexTEST.xsd')/xsd:schema/xsd:simpleType[@name='AssociationCodePersonType']/xsd:restriction[@base='xsd:token']/xsd:enumeration[@value='1']/xsd:annotation/xsd:documentation"/>line 2<br/>
***<xsl:value-of select="document('../Styles/XSLT/ndexTEST.xsd')/xsd:schema/xsd:simpleType[@name='AssociationCodePersonType']/xsd:restriction[@base='xsd:token']/xsd:enumeration[@value='1']/xsd:annotation/xsd:documentation"/>line 3<br/>
***<xsl:value-of select="document('http:ndexTEST.xsd')/xsd:schema/xsd:simpleType[@name='AssociationCodePersonType']/xsd:restriction[@base='xsd:token']/xsd:enumeration[@value='1']/xsd:annotation/xsd:documentation"/>line 4<br/>
***<xsl:value-of select="document('http://localhost/wsIBRClientSite/Styles/XSLT/ndexTEST.xsd')/xsd:schema/xsd:simpleType[@name='AssociationCodePersonType']/xsd:restriction[@base='xsd:token']/xsd:enumeration[@value='1']/xsd:annotation/xsd:documentation"/>line 5<br/>
***<xsl:value-of select="document('http:../Styles/XSLT/ndexTEST.xsd')/xsd:schema/xsd:simpleType[@name='AssociationCodePersonType']/xsd:restriction[@base='xsd:token']/xsd:enumeration[@value='1']/xsd:annotation/xsd:documentation"/>line 6<br/>
***<xsl:value-of select="document('file:ndexTEST.xsd')/xsd:schema/xsd:simpleType[@name='AssociationCodePersonType']/xsd:restriction[@base='xsd:token']/xsd:enumeration[@value='1']/xsd:annotation/xsd:documentation"/>line 7<br/>
***<xsl:value-of select="document('file:c:\inetpub\wwwroot\wsIBRClientSite\Styles\XSLT\ndexTEST.xsd')/xsd:schema/xsd:simpleType[@name='AssociationCodePersonType']/xsd:restriction[@base='xsd:token']/xsd:enumeration[@value='1']/xsd:annotation/xsd:documentation"/>line 8<br/>
***<xsl:value-of select="document('file://c/inetpub/wwwroot/wsIBRClientSite/Styles/XSLT/ndexTEST.xsd')/xsd:schema/xsd:simpleType[@name='AssociationCodePersonType']/xsd:restriction[@base='xsd:token']/xsd:enumeration[@value='1']/xsd:annotation/xsd:documentation"/>line 9<br/>
</xsl:template>

</xsl:stylesheet>

External Schema File (ndexTEST.xsd):


<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.ndex.gov/1.0.3" xmlns="http://www.ndex.gov/1.0.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:simpleType name="AssociationCodePersonType">
<xsd:annotation>
<xsd:documentation>A code list that enumerates types of relationships between persons.</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:token">
<xsd:enumeration value="1">
<xsd:annotation>
<xsd:documentation>Relationship Unknown</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="2">
<xsd:annotation>
<xsd:documentation>Otherwise Known</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="3">
<xsd:annotation>
<xsd:documentation>Spouse</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="4">
<xsd:annotation>
<xsd:documentation>Common-Law Spouse</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="5">
<xsd:annotation>
<xsd:documentation>Parent</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="6">
<xsd:annotation>
<xsd:documentation>Sibling</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="7">
<xsd:annotation>
<xsd:documentation>Child</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="8">
<xsd:annotation>
<xsd:documentation>Grandparent</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="9">
<xsd:annotation>
<xsd:documentation>Grandchild</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

irnbru

6:11 pm on Mar 16, 2005 (gmt 0)

10+ Year Member



xsltproc --version
Using libxml 20616, libxslt 10111 and libexslt 809
xsltproc was compiled against libxml 20614, libxslt 10111 and libexslt 809
libxslt 10111 was compiled against libxml 20614
libexslt 809 was compiled against libxml 20614

#######################

***Relationship Unknownline 1<br xmlns:jxdd="http://www.it.ojp.gov/jxdm/3.0.2" xmlns:ndex="http://www.ndex.gov/1.0.3" xmlns:inc="http://caseincidentreport.com/1.0.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
***Relationship Unknownline 2<br xmlns:jxdd="http://www.it.ojp.gov/jxdm/3.0.2" xmlns:ndex="http://www.ndex.gov/1.0.3" xmlns:inc="http://caseincidentreport.com/1.0.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
***Relationship Unknownline 3<br xmlns:jxdd="http://www.it.ojp.gov/jxdm/3.0.2" xmlns:ndex="http://www.ndex.gov/1.0.3" xmlns:inc="http://caseincidentreport.com/1.0.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
***Relationship Unknownline 4<br xmlns:jxdd="http://www.it.ojp.gov/jxdm/3.0.2" xmlns:ndex="http://www.ndex.gov/1.0.3" xmlns:inc="http://caseincidentreport.com/1.0.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
***Relationship Unknownline 5<br xmlns:jxdd="http://www.it.ojp.gov/jxdm/3.0.2" xmlns:ndex="http://www.ndex.gov/1.0.3" xmlns:inc="http://caseincidentreport.com/1.0.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
***Relationship Unknownline 6<br xmlns:jxdd="http://www.it.ojp.gov/jxdm/3.0.2" xmlns:ndex="http://www.ndex.gov/1.0.3" xmlns:inc="http://caseincidentreport.com/1.0.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
***Relationship Unknownline 7<br xmlns:jxdd="http://www.it.ojp.gov/jxdm/3.0.2" xmlns:ndex="http://www.ndex.gov/1.0.3" xmlns:inc="http://caseincidentreport.com/1.0.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
***Relationship Unknownline 8<br xmlns:jxdd="http://www.it.ojp.gov/jxdm/3.0.2" xmlns:ndex="http://www.ndex.gov/1.0.3" xmlns:inc="http://caseincidentreport.com/1.0.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
***Relationship Unknownline 9<br xmlns:jxdd="http://www.it.ojp.gov/jxdm/3.0.2" xmlns:ndex="http://www.ndex.gov/1.0.3" xmlns:inc="http://caseincidentreport.com/1.0.3" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

xalan-2.6.0

##################

***Relationship Unknownline 1<br xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:inc="http://caseincidentreport.com/1.0.3" xmlns:ndex="http://www.ndex.gov/1.0.3" xmlns:jxdd="http://www.it.ojp.gov/jxdm/3.0.2">
***Relationship Unknownline 2<br>
***Relationship Unknownline 3<br>
***Relationship Unknownline 4<br>
***Relationship Unknownline 5<br>
***Relationship Unknownline 6<br>
***Relationship Unknownline 7<br>
***Relationship Unknownline 8<br>
***Relationship Unknownline 9<br>

Different outputs from 2 different processors. I think my version of xsltproc is a bit old. I would check the version of the xslt processor you're using.

Made a minor change just to use my dummy xml file

<xsl:template match="/">
<xsl:apply-templates select="books/book"/>
</xsl:template>

<xsl:template match="books/book">
.... as per your template........
</xsl:template>

john_k

6:41 pm on Mar 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you very much for taking the time to help. I am doing this via .Net, so it is using the System.Xml.Xsl.XslTransform object.

Just for grins, I tried this with a classic ASP page and it works. The difference is that the ASP functions utilize the MSXML DOM objects.

MicroSoft support staff will never be in want of a job, that's for sure.

It is quite possibly an issue with security rights to a temp directory or something like that. So I will pursue that angle for awhile. Thanks again!

john_k

7:27 pm on Mar 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Okay. The solution is that I need to pass in an instance of an XmlUrlResolver to the Transform method. Why MS couldn't state that simply somewhere is beyond me. It does (sort of) show up under their documentation for the XmlUrlResolver class. But if I had known to look there, then I probably wouldn't have had this question to begin with.

Anyway, here is the simple phrase that would have helped: If you are using .Net to do XSLT and you want to use the document() function, then you need to pass an XmlUrlResolver instance in the call to the Transform method. There are probably exceptions.

Hopefully that will show up in Google for the next person that has this question.