xsl-list
[Top] [All Lists]

Re: [xsl] XML Question

2006-10-03 16:06:44
On 10/3/06, LINKE Markus <markus(_dot_)linke(_at_)linke(_dot_)de> wrote:
The XSL is taken from Dimitres link by the way, so I did not do any 
modifications.


Of course, if you do not do any modifications you're going to receive
the results this stylesheet was producing (and still is) 5 years ago.

You need to modify the xsl:variable named "theParmNodes"  in this way:

<xsl:variable name="theParmNodes" select="//text()"/>

then apply the transformation against your xml document.

The result is:

/a/b/c/text()
/a/b/d/text()


In case a more generic expression selecting all leaf nodes of the
document is needed, one can use:

<xsl:variable name="theParmNodes" select="//node()[not(node())]"/>

but in the case of the originally provided xml document both
expressions select the two text nodes.

And Dr. Kay is absolutely right, no conversion of the RTF to a regular
tree is necessary if we only need to use its string value -- 5 years
ago I didn't yet know this fact :o)


--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




----- LINKE Markus <markus(_dot_)linke(_at_)linke(_dot_)de> wrote:
> 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(_dot_)online(_at_)xs4all(_dot_)nl> 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
> > >
> > >
> >
> >
> >
> --~------------------------------------------------------------------
> > XSL-List info and archive:
> http://www.mulberrytech.com/xsl/xsl-list
> > To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> > or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
> > --~--
>
>
> --~------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
> --~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>