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

Re: constraints - odd question

  • From: "G. Ken Holman" <gkholman@C...>
  • To: xml-dev@l...
  • Date: Fri, 06 Jul 2001 17:20:08 -0400

xsl constraints
At 01/07/06 16:49 -0400, Simon St.Laurent wrote:
>I want to make certain that no elements have the same names as their
>siblings.
>...
>I'm looking for something more
>like a DTD - an XSLT style sheet might be acceptable.

Not awkward to do in XSLT ... check the code below.  I am emitting a crude 
XPtr to the node that has a following sibling of the same name.  Of course 
this could be changed to report the errors using an XML instance.

I hope this helps.

........................ Ken

T:\>type checksibs.xml
<?xml version="1.0" encoding="utf-8"?>
<a>
   <b>
     <c>
     </c>
     <d>
     </d>
   </b>
   <e>
     <c>
     </c>
     <d>
     </d>
     <e>
     </e>
     <c>
       <e>
         <c>
         </c>
         <d>
         </d>
         <e>
         </e>
         <c>
         </c>
       </e>
     </c>
   </e>
</a>
T:\>type checksibs.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version="1.0">

<xsl:output method="text"/>

<xsl:template match="*">
   <xsl:if test="following-sibling::*[name(.)=name(current())]">
     <xsl:message>
       <xsl:for-each select="ancestor-or-self::*">
         <xsl:text/>/<xsl:value-of select="name(.)"/>[<xsl:text/>
         <xsl:number/>]<xsl:text/>
       </xsl:for-each>
       <xsl:text> has following sibling with same name</xsl:text>
     </xsl:message>
   </xsl:if>
   <xsl:apply-templates/>
</xsl:template>

<xsl:template match="text()"/>

</xsl:stylesheet>

T:\>saxon checksibs.xml  checksibs.xsl
/a[1]/e[1]/c[1] has following sibling with same name
/a[1]/e[1]/c[2]/e[1]/c[1] has following sibling with same name

T:\>

--
G. Ken Holman                      mailto:gkholman@C...
Crane Softwrights Ltd.               http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0     +1(613)489-0999   (Fax:-0995)
Web site:     XSL/XML/DSSSL/SGML/OmniMark services, training, products.
Book:  Practical Transformation Using XSLT and XPath ISBN 1-894049-06-3
Article: What is XSLT? http://www.xml.com/pub/2000/08/holman/index.html
Next public instructor-led training:      2001-08-12,08-13,09-19,10-01,
-                                               10-04,10-22,10-29,02-02

Training Blitz: 3-days XSLT/XPath, 2-days XSLFO in Ottawa 2001-10-01/05


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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.