This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: text() and not()


I'm not sure if this answers your question because I can't tell if all the
elements you want to treat like this have the same construction, and I'm not
sure if you literally want "xref" in the output, but here is a simple set of
templates that uses recursion to output what you say you want.

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

<xsl:template match="/">
<result>
 <xsl:apply-templates select='title'/>
</result>
</xsl:template>

<xsl:template match='title'>
<xsl:call-template name='matchtext'/>
</xsl:template>

<xsl:template name='matchtext'>
<xsl:copy-of select='text()'/>
<xsl:for-each select='*'>
 <xsl:if test='name()="xref"'>xref</xsl:if>
 <xsl:call-template name='matchtext'/>
</xsl:for-each>
</xsl:template>

<xsl:template match='*'/>
</xsl:stylesheet>

============= Result ==============
<result>
  Renew LP Piston Seal (Fig 5.5.1

 xref
    )
  </result>

(I wrapped the output in a <result> element - of course, it could be
anything.  You can get rid of the extra whitespace by using
normalize-space(text()) if you care about that).

If you want to output something else instead of "xref" it should be clear
where to make corresponding changes.

Cheers,

Tom P

[Andrew Welch]>
> I have a problem with the default template, text() and an element within
> another element.
>
> <title>
>   Renew LP Piston Seal (Fig 5.5.1
>   <xref xrefid="F5.5.1" xidtype="FIGURE">
>     )
>   </xref>
> </title>
>
> I want this to output as:
>
> Renew LP Piston Seal (Fig 5.5.1 xref )
>
> where 'xref' will be replaced by a graphic.
>
> I am overriding the default template using
>
> <xsl:template match=text()/>
>
> because there are several hundred elements that arent for display.
However,
> matching <xref> with a separate template and overriding the default
template
> in this way means 'xref' is moved outside the (fig).  I have been told to
> override the default template with a predicate to not include <title> and
> use the default template to output the contents of <title>.
>



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]