Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: accessing xs:appinfo while transforming a Schema (xsd) accessing xs:appinfo while transforming a Schema (xsd)To: NULL Date: 11/4/2005 3:51:00 PM I'm transforming a schema file (xsd) and would like to get at the data
contained in an xs:appinfo element. If I do this:
<xsl:value-of select="xs:annotation/xs:appinfo/myData"/>
I get nothing. But if I do this:
<xsl:value-of select="name(xs:annotation/xs:appinfo/*[1])"/>
I get "myData". So, apparantly xsl can read the xml, it just won't read
it the way I want it to.
Really all I want to do is check for the existence of a node within
xs:appinfo. I can do it using the name() function, as long as it is the
first node under xs:appinfo (or I otherwise know it's index). But I
can't guarantee that it will always be the first node. (Okay, well
maybe I can for now, but I don't want to rely on that. What happens
when I want to add a second optional node?)
How do I get at that node?
Here's a quick repro sample:
XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="myRootElement">
<xs:annotation>
<xs:documentation>
This element's appinfo does not contain a "myData" node.
</xs:documentation>
<xs:appinfo/>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="foo" type="xs:string">
<xs:annotation>
<xs:documentation>
This element's appinfo does not contain a "myData" node.
</xs:documentation>
<xs:appinfo>
<myData>1</myData>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="bar" type="xs:string">
<xs:annotation>
<xs:documentation>
This element's appinfo does not contain a "myData" node.
</xs:documentation>
<xs:appinfo/>
</xs:annotation>
</xs:element>
<xs:element name="foobar" type="xs:string">
<xs:annotation>
<xs:documentation>
This element's appinfo does not contain a "myData" node.
</xs:documentation>
<xs:appinfo>
<myData>1</myData>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="xs:schema">
<table>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="xs:element">
<tr>
<td>Element:</td>
<td><xsl:value-of select="@name"/></td>
</tr>
<tr>
<td>Notes:</td>
<td><xsl:value-of select="xs:annotation/xs:documentation"/></td>
</tr>
<tr>
<td>xs:annotation/xs:appinfo/myData:</td>
<td><xsl:value-of select="xs:appinfo/myData"/></td>
</tr>
<tr>
<td>name(xs:annotation/xs:appinfo/*[1]):</td>
<td>
<xsl:value-of select="name(xs:annotation/xs:appinfo/*[1])"/>
</td>
</tr>
<tr>
<td>xs:annotation/xs:appinfo/*[1]:</td>
<td><xsl:value-of select="xs:annotation/xs:appinfo/*[1]"/></td>
</tr>
<tr>
<td><br/>-<br/><br/></td>
</tr>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="xs:annotation"/>
</xsl:stylesheet>
At this point, my best hack solution is to just add a unique string in
the appinfo node and search for it using contains. Any suggestions for
a more elegant solution is greatly appreciated!
-ivan.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
