[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Selecting First Direct Sibling

Subject: RE: Selecting First Direct Sibling
From: "Bjorndahl, Brad" <brad.bjorndahl@xxxxxxxxxxxxxxxx>
Date: Wed, 22 Aug 2007 13:04:47 -0400
RE:  Selecting First Direct Sibling
This thread has been drilling down into extremely fine details that are
required only because the original XML has been misused.

There is using proper markup and there is using markup properly.

That is, the OP is processing valid comment elements and text nodes, but
putting 'invalid' information into the comments. Schemas have documentation
elements for this stuff, and these elements allow elements from other
namespaces, so the markup is unrestricted. I've done it and it is simple,
unambiguous, and clean.

I understand that the OP may have no choice, maybe the XML can't be changed so
we need to make XSL do backflips, but these DTD/schema/whitespace
complications contradict the spirit of XML.

Brad


-----Original Message-----
From: Wasiq Shaikh [mailto:wasiq911@xxxxxxxxxxx]
Sent: August 20, 2007 1:35 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Selecting First Direct Sibling

Hello,

I'm having a weird and frustrating problem. I have two XSL files
(XPath1.0/Xalan2.7J). Both do the same thing. One (mine) is more robust and
has a bit more processing. The other more simplistic and different formatting
but with the same goal in mind. That goal is to produce a flat list of
elements and its attributes from an XML Schema document.

The objective here is to get the comment block directly after an element
and/or attribute declaration.

Example:

<xsd:element name="blah">
<!-- This is a comment about the element blah -->
   <xsd:attribute name="someAttribute"/>
   <xsd:attribute name="blahAttribute"/>
   <!-- This is a comment about the attribute blahAttribute under element blah
--> </xsd:element>

Let's focus on grabbing the comment block under attributes. In the simplistic
XSL tranformation we have this:

<xs:stylesheet exclude-result-prefixes="xsd"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:xs="http://www.w3.org/1999/XSL/Transform"
   version="1.0"
   xmlns:xalan="http://xml.apache.org/xslt">

   <xs:output indent="yes" xalan:indent-amount="3"/>

<xs:template match="/">
   <xs:element name="Repository">
      <xs:element name="Elements">
         <xs:apply-templates select="/*/*"/>
      </xs:element>
   </xs:element>
</xs:template>

<xs:template match="xsd:element[@name]">
   <xs:element name="{@name}">
      <xs:if test="string(@type)">
         <xs:attribute name="type">
            <xs:value-of select="@type"/>
         </xs:attribute>
      </xs:if>
      <xs:for-each select="*[name()='xsd:simpleType' or
name()='xsd:complexType']">
         <xs:apply-templates select="*"/>
      </xs:for-each>
   </xs:element>
</xs:template>

<xs:template match="xsd:attribute">
   <xs:element name="attribute">
      <xs:attribute name="name">
         <xs:value-of select="@name"/>
      </xs:attribute>
      <xs:copy-of select="following-sibling::node()[1][self::comment()]"/>
   </xs:element>
</xs:template>

<xs:template match="xsd:sequence|xsd:choice">
   <xs:apply-templates select="*"/>
</xs:template>

<xs:template match="node()|@*"/>

</xs:stylesheet>

This works great. It grabs the comment block directly after an attribute. If
it doesn't exist it doesn't process anything. The output will be this:

<blah>
   <attribute name="someAttribute"/>
   <attribute name="blahAttribute"/>
   <!-- This is a comment about the attribute blahAttribute under element blah
--> </blah>

So, I take this simplistic stylesheet and make it more robust, more
descriptive, added a few changes to the format, some more descriptive
attributes, process complexTypes and extensions and so forth ... However, the
comment grab doesn't work.

------

OHHH ... SOB!!! I figured it out! [40 minutes later] I'll leave the original
message I was typing so others will understand the problem.

Apparently, adding/removing this line

<xsl:strip-space elements="xsd:complexType"/>

makes the script work/not work. This doesn't make sense to me .. what does
this have to do with processing comments?

W.S

_________________________________________________________________
Share More On Messenger with a Windows Live Space
http://spaces.live.com/?mkt=en-ca

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.