xsl-list
[Top] [All Lists]

RE: [xsl] Copy element content to another nested empty element

2008-05-02 05:48:23
[Sorry if this starts another thread - this is my first reply.  I am
subscribing to the digest and I did not receive a direct reply to my
post.  So I am replying via the digest.  I am sure I am not doing this
correctly and I apologize - feel free to explain the proper procedure
- thanks!]

Anyway, thanks for the reply!  We are 90% there.  Except for a minor
typo ("<xslapply-templates" - missing colon), I thought you had done
it! As the HTML rendered perfectly.  However, on closer inspection I
realized the the entire option elements had be copied and not just
their content as I intended originally.  Here is a snippet:

===== Current Result =====
The first phrase element is <span class="phrase"><option id="value1">a
simple phrase</option></span>.  And the second phrase element is <span
class="phrase"><option id="value2">also a simple
phrase</option></span>, and the third phrase element <span
class="phrase"><option id="value3">could be a simple phrase</option>
</span> as well.
=====

===== Desired Result =====
The first phrase element is <span class="phrase">a simple
phrase</span>.  And the second phrase element is <span
class="phrase">also a simple phrase</span>, and the third phrase
element <span class="phrase">could be a simple phrase</span> as well.
=====

I tried tacking on a /text():

<xsl:apply-templates
select="//lists/list[(_at_)name=$list]/option[(_at_)id=$phrase]/text()"/>

But that broke it it again.  And I can see that I just flattened
things out again.

Then I tried a match="option" template but that was unsuccessful.

So the question is how can we follow the nested nodes, but copy only
the CONTENT of the nodes?

Thanks again for your help.  And again my apologies for not knowing
how to properly use this mailing list...

-Kiel


 Date: Thu, 1 May 2008 15:56:10 +0100
 To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
 From: "Michael Kay" <mike(_at_)saxonica(_dot_)com>
 Subject: RE: [xsl] Copy element content to another nested empty element
 Message-ID: <975ECD4F953A44948E3CF800D8AF4E9E(_at_)Sealion>

 I think your basic problem is here:

 <xsl:template match="phrase">
  <xsl:variable name="phrase" select="@name"/>
  <xsl:variable name="list" select="@list"/>
  <span class="phrase"><xsl:value-of
 select="//lists/list[(_at_)name=$list]/option[(_at_)id=$phrase]"/></span>
 </xsl:template>

 You are taking the "value-of" an option element (which flattens it to a
 string), but the option element actually has internal structure that needs
 to be further processed. So try this instead:

 <xsl:template match="phrase">
  <xsl:variable name="phrase" select="@name"/>
  <xsl:variable name="list" select="@list"/>
  <span class="phrase">
     <xslapply-templates
 select="//lists/list[(_at_)name=$list]/option[(_at_)id=$phrase]"/>
  </span>
 </xsl:template>

 I haven't tested this, but it should be the only change you need to make.
 Except that if your data contains cycles, your code will probably blow up
 with a "stack full" error.

 Michael Kay
 http://www.saxonica.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>