Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


accessing xs:appinfo while transforming a Schema (xsd)

From: gilly3 <news@------------.--->
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.


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent