[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] trying to search and replace within a xsl:for-each tag


Subject: [xsl] trying to search and replace within a xsl:for-each tag
From: Jamie DelleMonache <jamied@xxxxxxxxxxxxxxxx>
Date: Thu, 16 Feb 2012 17:22:10 -0800

Kind of a newbie at XSLT so please bare with me:

I am attempting to produce a plain text document from an xml file. The
structure of my source XML is as follows:

<textObject>

           <metadata>this is metadata A</metadata>

           <text>This is graph number one<break type="paragraph"/>This is
graph number two<text>

</textObject>

<textObject>

           <metadata>this is metadata B</metadata>

           <text>this is graph number one<break type="paragraph"/>this is
graph number two<text>

</textObject>

=======================================================================

The desired result would look llike this:

this is metadata A
This is graph number one(hard return here)

This is graph number two

this is metadata B

This is graph number one (hard return here)

This is graph number two


My methodology:

I'm attempting to use the xsl:for-each tag to process all the textObject
elements, and then output the 'value of' the the text nodes of the metadata
and text elements. This works fine, but obviously there are no hard returns in
the result.

To transform the <break type=paragraph> tags to hard returns (&#13;) I have
tried xls:choose and xsl:if within the xsl:for-each element, and no
luck. I guess the big question is: is this methodology valid? I can make this
work using another approach but from a logic perspective; its not as robust as
using <xsl:for-each> Below is a sample from my style sheet



<xsl:variable name="copy">

<xsl:for-each select="//ns:textObject">

           <xsl:call-template name="story"/>

           <xsl:choose>

               <xsl:when test="ns:break[@type='paragraph']">

               <xsl:text >&#13;</xsl:text>

               </xsl:when>

           </xsl:choose>

           <xsl:value-of select="ns:metaData/ns:metaDataValue/ns:string"/>

           <xsl:copy-of select="normalize-space(ns:text)"/

           <xsl:text>&#13;</xsl:text>
       </xsl:for-each>

</xsl:variable>



Any help would be appreciated, thanks

j.
_________________________________

Jamie DelleMonache | Solutions Specialist

MEI  |  610 Old York Rd, Suite 250  |  Jenkintown, PA 19046
P: 215-886-5662 x282 | F: 215-886-5681
E-Mail: jdellemonache@xxxxxxxxx
http://www.maned.com


Current Thread
Keywords