xsl-list
[Top] [All Lists]

RE: [xsl] Filtering child text nodes by node name

2007-02-22 12:23:18
I figured it out. 

<xsl:template match="title>
   <xsl:element name="topic-title">
      <xsl:for-each select=".//text()[not(ancestor::indexterm)]">
           <xsl:value-of select="."/>
      </xsl:for-each>
   </xsl:element>
</xsl:template>

Thank you for the suggestion, Mukul. It prompted me to evaluate the text
nodes individually.


-----Original Message-----
From: Anderson, Paul [mailto:Paul(_dot_)Anderson(_at_)compuware(_dot_)com] 
Sent: Thursday, February 22, 2007 1:40 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Filtering child text nodes by node name

While this is an interesting possibility, I cannot use it. I should have
indicated that the <indexterm> element inside the <title> is optional.
Consider my first attempt:

<xsl:template match="title>
   <xsl:element name="topic-title">
       <xsl:value-of select="."/
   </xsl:element>
</xsl:template>

This works perfectly in all cases _except_ when there is one or more
<indexterm> elements in the title.

-----Original Message-----
From: Mukul Gandhi [mailto:gandhi(_dot_)mukul(_at_)gmail(_dot_)com]
Sent: Thursday, February 22, 2007 1:31 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Filtering child text nodes by node name

I hope following should work:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">

 <xsl:output method="xml" indent="yes"/>

 <xsl:template match="title">
   <topic-title><xsl:apply-templates
select="indexterm[1]/preceding-sibling::node()" /></topic-title>
</xsl:template>

 <xsl:template
match="node()[following-sibling::indexterm[not(preceding-sibling::indext
erm)]]">
   <xsl:choose>
     <xsl:when test="self::text()">
       <xsl:copy-of select="." />
     </xsl:when>
     <xsl:otherwise>
       <xsl:apply-templates />
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>

</xsl:stylesheet>

This produces output:

<?xml version="1.0" encoding="UTF-8"?>
<topic-title>Configuring the process command  </topic-title>

With input XML:

<?xml version="1.0" encoding="UTF-8"?>
<title>Configuring the <command>process</command> command  <indexterm>
   <primary>In title</primary>
   <secondary>first</secondary>
 </indexterm>
 <indexterm>
   <primary>In title</primary>
   <secondary>second</secondary>
 </indexterm>
</title>

You could try to correct the extra newline printed at the end.

On 2/22/07, Anderson, Paul <Paul(_dot_)Anderson(_at_)compuware(_dot_)com> wrote:
Greetings All,

I am processing the following sample source:

...
<title>Configuring the <command>process</command> command  <indexterm>
   <primary>In title</primary>
   <secondary>first</secondary>
 </indexterm>
 <indexterm>
   <primary>In title</primary>
   <secondary>second</secondary>
 </indexterm>
</title>
...

I already have scripting in place to process the <indexterm> elements 
inside the <title> and move them to another location in the output.
The problem is that I need to output a title that ignores the child 
elements but retains their content but _not_ if the child element is 
an indexterm. The output I need is:

<topic-title>Configuring the process command</topic-title>

Naturally, I started with something like the following:

<xsl:template match="title>
  <xsl:element name="topic-title">
       <xsl:value-of select="."/
  </xsl:element>
</xsl:template>

Which generated the output:
<topic-title>Configuring the process commandIn titlefirstIn 
titlesecond</topic-title>

I've been playing around with various predicates on text nodes but 
they don't provide the desired output. For example:

<xsl:template match="title>
  <xsl:element name="topic-title">
       <xsl:value-of select="./text()[not(ancestor::indexterm)]"/
  </xsl:element>
</xsl:template>

Generates the following output:
<topic-title>Configuring the </topic-title>

Any assistance is appreciated.

Best regards,

Paul Anderson
Compuware Corporation
The contents of this e-mail are intended for the named addressee only.
It contains information that may be confidential. Unless you are the
named addressee or an authorized designee, you may not copy or use it,
or disclose it to anyone else. If you received it in error please notify
us immediately and then destroy it.



--
Regards,
Mukul Gandhi

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

The contents of this e-mail are intended for the named addressee only.
It contains information that may be confidential. Unless you are the
named addressee or an authorized designee, you may not copy or use it,
or disclose it to anyone else. If you received it in error please notify
us immediately and then destroy it. 

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

The contents of this e-mail are intended for the named addressee only. It 
contains information that may be confidential. Unless you are the named 
addressee or an authorized designee, you may not copy or use it, or disclose it 
to anyone else. If you received it in error please notify us immediately and 
then destroy it. 

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