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

Re: XML Question

Subject: Re: XML Question
From: LINKE Markus <markus.linke@xxxxxxxx>
Date: Tue, 3 Oct 2006 17:27:34 -0500 (CDT)
count preceding sibling local name
I think I missunderstood something ...

I have this xml-file:

<?xml-stylesheet type="text/xsl" href="xml2html.xsl"?>
<a>
    <b>
        <c>ccc</c>
    </b>
    <d>
        <e>eee</e>
    </d>
</a>

and this stylesheet:

<xsl:stylesheet version='1.0'
   xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
   xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
   >
   
   <xsl:output method="text"/>
   <xsl:variable name="theParmNodes" select="//namespace::*[local-name() =
      'myNamespace']"/>
   <xsl:template match="/">
      <xsl:variable name="theResult">
         <xsl:for-each select="$theParmNodes">
            <xsl:variable name="theNode" select="."/>
            <xsl:for-each select="$theNode |
               $theNode/ancestor-or-self::node()[..]">
               <xsl:element name="slash">/</xsl:element>
               <xsl:choose>
                  <xsl:when test="self::*">			
                     <xsl:element name="nodeName">
                        <xsl:value-of select="name()"/>
                        <xsl:variable name="thisPosition" 
                           select="count(preceding-sibling::*[name(current()) = 
                           name()])"/>
                        <xsl:variable name="numFollowing" 
                           select="count(following-sibling::*[name(current()) = 
                           name()])"/>
                        <xsl:if test="$thisPosition + $numFollowing > 0">
                           <xsl:value-of select="concat('[', $thisPosition +
                              1, ']')"/>
                        </xsl:if>
                     </xsl:element>
                  </xsl:when>
                  <xsl:otherwise> <!-- This node is not an element -->
                     <xsl:choose>
                        <xsl:when test="count(. | ../@*) = count(../@*)">	
                           <!-- Attribute -->
                           <xsl:element name="nodeName">
                              <xsl:value-of select="concat('@',name())"/>
                           </xsl:element>
                        </xsl:when>		
                        <xsl:when test="self::text()">	<!-- Text -->
                           <xsl:element name="nodeName">
                              <xsl:value-of select="'text()'"/>
                              <xsl:variable name="thisPosition" 
                                 select="count(preceding-sibling::text())"/>
                              <xsl:variable name="numFollowing" 
                                 select="count(following-sibling::text())"/>
                              <xsl:if test="$thisPosition + $numFollowing > 0">
                                 <xsl:value-of select="concat('[', $thisPosition + 
                                    1, ']')"/>
                              </xsl:if>
                           </xsl:element>
                        </xsl:when>		
                        <xsl:when test="self::processing-instruction()">
                           <!-- Processing Instruction -->
                           <xsl:element name="nodeName">
                              <xsl:value-of select="'processing-instruction()'"/>
                              <xsl:variable name="thisPosition" 
                                 select="count(preceding-sibling::processing-instruction())"/>
                              <xsl:variable name="numFollowing" 
                                 select="count(following-sibling::processing-instruction())"/>
                              <xsl:if test="$thisPosition + $numFollowing > 0">
                                 <xsl:value-of select="concat('[', $thisPosition + 
                                    1, ']')"/>
                              </xsl:if>
                           </xsl:element>
                        </xsl:when>		
                        <xsl:when test="self::comment()">	<!-- Comment -->
                           <xsl:element name="nodeName">
                              <xsl:value-of select="'comment()'"/>
                              <xsl:variable name="thisPosition" 
                                 select="count(preceding-sibling::comment())"/>
                              <xsl:variable name="numFollowing" 
                                 select="count(following-sibling::comment())"/>
                              <xsl:if test="$thisPosition + $numFollowing > 0">
                                 <xsl:value-of select="concat('[', $thisPosition + 
                                    1, ']')"/>
                              </xsl:if>
                           </xsl:element>
                        </xsl:when>		
                        <!-- Namespace: -->
                        <xsl:when test="count(. | ../namespace::*) = 
                           count(../namespace::*)">
                           
                           <xsl:variable name="apos">'</xsl:variable>
                           <xsl:element name="nodeName">
                              <xsl:value-of select="concat('namespace::*', 
                                 '[local-name() = ', $apos, local-name(), $apos, ']')"/>
                              
                           </xsl:element>
                        </xsl:when>		
                     </xsl:choose>
                  </xsl:otherwise>			
               </xsl:choose>
            </xsl:for-each>
            <xsl:text>&#xA;</xsl:text>
         </xsl:for-each>
      </xsl:variable>
      <xsl:value-of select="msxsl:node-set($theResult)"/>
   </xsl:template>
</xsl:stylesheet>

Initially I tried with the XSL-debugger of Oxygen, but that brought the error mentioned below; if I try it just with Internet Explorer I get no result at all (blank page).

Did I forget a step?

Cheers,
Markus

----- Abel Braaksma <abel.online@xxxxxxxxx> wrote:
> Markus,
> 
> Depending on your processor, you can try:
> 
> <xsl:value-of select="exslt:node-set($theResult)"/>
> where you bind exslt (or whatever prefix you like) to
> "http://exslt.org/common"
> 
> <xsl:value-of select="saxon:node-set($theResult)"/>
> where you bind saxon (or whatever prefix you like) to
> "http://saxon.sf.net" (but I remember saxon supports exslt extensions,
> so you can use the previous
> 
> If you use a browser processor, the original should work like below, I
> think (never tried it myself) when you are in IE, but when you are in
> Gecko, you are out of luck, there is no node-set extension function
> available in TransformIIX (the xslt parser for Gecko). In Opera:
> please see a recent discussion on this list about the subject.
> 
> In any case, best chances are that exslt nodeset will work.
> 
> Cheers,
> Abel Braaksma
> http://www.nuntia.nl
>  
> 
> 
> 
> LINKE Markus wrote:
> > I've tried it but I receive an:
> >
> > SystemID: xxx.xsl
> > Location: 98:0
> > Description: The URI urn:schemas-microsoft-com:xslt does not
> identify an external Java class
> >
> > error message at this location:
> >
> >       </xsl:variable>
> >       <xsl:value-of select="msxsl:node-set($theResult)"/> <!-- here
> -->
> >    </xsl:template>
> >
> > ???
> >
> > Thanks for your help!
> > Markus

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.