xsl-list
[Top] [All Lists]

Re: [xsl] Searching in Sub-children from an Array

2006-12-04 09:58:17
Houman Khorasani wrote:

  Hi

There is somewhere in the xml document a <steps> element that
contains several Ids:

<Steps>111,222,333,444</Steps>

  Something like the following can help you.  Warning: not tested!

    <xsl:key name="my:id" match="*[(_at_)id]" use="@id"/>

    <xsl:function name="my:resolve-path" as="element()*">
      <xsl:param name="root" as="node()"/>
      <xsl:param name="path" as="xs:string"/>
      <xsl:variable name="steps" select="tokenize($path, ',')"/>
      <xsl:if test="exist($steps)">
        <xsl:sequence select="
            my:resolve-path-1(key('my:id', $steps[1], $root),
                              $steps)"/>
      </xsl:if>
    </xsl:function>

    <xsl:function name="my:resolve-path-1" as="element()*">
      <xsl:param name="current" as="element()"/>
      <xsl:param name="steps"   as="xs:string*"/>
      <xsl:sequence select="
          $current,
          if ( exist($steps) ) then
            my:resolve-path-1($current/*[(_at_)id eq $steps[1]],
                              $steps[position() gt 1])
          else
            ()"/>
    </xsl:function>

  You can then get the resolved path (that is, a sequence of elements,
whose the ids are the same as in steps, in the same order) by:

    <xsl:sequence select="my:resolve-path(/, steps)"/>

  Regards,

--drkm

























        

        
                
___________________________________________________________________________ 
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Profitez des connaissances, des opinions et des expériences des internautes sur 
Yahoo! Questions/Réponses 
http://fr.answers.yahoo.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>
--~--