Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] XML Question

From: LINKE Markus <markus.linke@-------->
To:
Date: 10/3/2006 10:28:00 PM
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


transparent
Print
Mail
Digg
delicious
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