xsl-list
[Top] [All Lists]

RE: [xsl] Recursive Split

2007-11-15 01:57:17
There is a two-argument version of id() in XPath 2.0. The first argument is
the ID value that you want to find, the second identifies the document that
you want to search, which defaults to "/". If the context node is an atomic
value then you need to supply the second argument.

But if it's really as simple as this:

    <xsl:variable name="item" select="tokenize($item, '\s+')"/>
    <xsl:for-each select="$item">
      <xsl:value-of select="id(.)"/>
    </xsl:for-each>

then just do 

<xsl:value-of select="for $t in tokenize($item, '\s+') return id($t)"/>

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Alice Ju-Hsuan Wei [mailto:ajwei(_at_)indiana(_dot_)edu] 
Sent: 15 November 2007 01:28
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Recursive Split

Hi,

   Looks like now I am trying to use the tokenize function, 
but it appears that it does not allow me to use id() with it. 
When I ran the XSLT, it tells me this: F Cannot select a node 
here: the context item is an atomic value, with the errors 
pointing to the line where it says id(.).

Here is my XML:

              <listItem>
                   <to_do xml:id="cheese">Cheddar Cheese</to_do>
               </listItem>
                <listItem>
                   <to_do xml:id="beef">Chuck Steak</to_do>
               </listItem>
                <listItem>
                   <to_do xml:id="vegetables">Brocoli, Beans, 
Carrots</to_do>
               </listItem>
               <listItem>
                   <to_do xml:id="milk">Dean's Low Fat Milk 2%</to_do>
               </listItem>

  <do>
   <date>2007-11-14</date>
  <list>milk cheese vegetables beef</list>
  <limit_price>20</limit_price>
   <do>
  Current XSL:

  <xsl:template name="do_list">
   <xsl:variable name="do" select="list">
   <xsl:variable name="item" select="tokenize($item, '\s+')"/>
    <xsl:for-each select="$item">
   <xsl:value-of select="id(.)"/>
   </xsl:for-each>
   </xsl:template>

  Intended Output in HTML:

     <ul>
                   <li>Cheddar Cheese</li>
                  <li>Chuck Steak</li>
                  <li>Brocololi, Beans, Carrots</li>
                  <li>Dean's Low Fat Milk 2%</li></ul>

   Is it possible to parse these elements in the XML 
recursively with the id()? I do not want to print out the 
attributes only, but I want it to print out the id of the attribute.

Thanks in advance.

Alice



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