xsl-list
[Top] [All Lists]

Re: [xsl] matching elements of a list

2007-05-08 14:43:45
That's challenging and very elegant, George.
I'll learn about lists as to see whether I can use them with nodes
in the same way as you applied them to text.

Many thanks, George
(I've got to apologize for thinking this weren't possible)


George Cristian Bina wrote:
Hi Rolf,

In XSLT 2.0 you can define a function to get the list of elements, see
an example below:

<?xml version='1.0'?>
<xsl:transform version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:g="http://www.oxygenxml.com/george";>
    <xsl:output method="text"/>

    <xsl:function name="g:getList">
        <xsl:param name="node"/>
        <xsl:param name="root"/>
        <xsl:sequence select="if ($node) then ($node,
g:getList($root/ln[(_at_)s=$node]/@d, $root)) else ()"/>
    </xsl:function>

    <xsl:template match="st">
        <xsl:value-of select="g:getList(@ix, /root)" separator="->"/>
    </xsl:template>
</xsl:transform>

a->g->f
b->e->c->d

Regards,
George
---------------------------------------------------------------------
George Cristian Bina - http://aboutxml.blogspot.com/
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


Jeff Sese wrote:
try this stylesheet, i think this would work (if i guessed your
requirements right).

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
 <xsl:template match="/">
   <xsl:apply-templates select="root/st"/>
 </xsl:template>
 <xsl:template match="st">
   <xsl:value-of select="concat(@ix,':')"/>
   <xsl:apply-templates
select="following-sibling::ln[(_at_)s=current()/@ix]"/>
   <xsl:text>&#xa;</xsl:text>
 </xsl:template>
 <xsl:template match="ln">
   <xsl:value-of select="concat(' ', @d)"/>
   <xsl:apply-templates
select="following-sibling::ln[(_at_)s=current()/@d]"/>
 </xsl:template>
</xsl:stylesheet>

-- 
Jeff


Rolf Schumacher wrote:
do I have reached the limits of xpath?

if several linked lists are contained in one document how to match all
nodes belonging to a specific start node?

The following example may illustrate my question:

Input:
<root>
    <st ix="a"/>
    <st ix="b"/>
    <el ix="c"/>
    <el ix="d"/>
    <el ix="e"/>
    <el ix="f"/>
    <el ix="g"/>

    <ln s="a" d="g"/>
    <ln s="g" d="f"/>

    <ln s="b" d="e"/>
    <ln s="e" d="c"/>
    <ln s="c" d="d"/>
</root>

disired output:

a: g f
b: e c d

How to accomplish that by XSLT (2.0)?
Even your answer "I know for sure that there is not elegant way"
or "You got to extend the processor by some Java function"
would help.

--~------------------------------------------------------------------
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>