OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: constraints - odd question



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@CraneSoftwrights.com
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