Jump to content

adding a space through xslt


taffmeister

Recommended Posts

Hi all,I am fairly new to xslt and trying to get to grips with it.I have cuurrently in my xslt file the following: <xsl:element name="text"> <xsl:copy-of select="../../Order_Text[@Key=$textversion]/ad_database_text"/> </xsl:element>which gives me the following in my xml output:<text> <ad_database_text> <text>DOYLE.</text> <BreakPoint/> <text>Doris works in the Hr Department.</text> </ad_database_text></text>as you can see there are multiple <text> nodes which doesn't seem write.If I amend the xslt to read: <xsl:element name="text"> <xsl:value-of select="../../Order_Text[@Key=$textversion]/ad_database_text"/> </xsl:element>I get a better result which reads: <text>DOYLE.Doris works in the Hr Department.</text> Which is much better, But I need to add a space after DOYLE.Is this simple to do?RegardsTaff

Link to comment
Share on other sites

The simplest way to do it is probably to loop over all text elements in the input, and output them with a space following, unless they're the very last element, in which case they should be outputted without a space.To put it in code:

<xsl:element name="text"><xsl:for-each select="../../Order_Text[@Key=$textversion]/ad_database_text/text"><xsl:value-of select="." /><xsl:if test="position()!=last()"> </xsl:if></xsl:for-each></xsl:element>

Link to comment
Share on other sites

Do you want to insert a space because of the "BreakPoint" element between the "text" elements? In that case the proper way with XSLT is to write a template doing that e.g.

<xsl:template match="BreakPoint"><xsl:text> </xsl:text></xsl:template>

and then to use apply-templates e.g.

<xsl:template match="ad_database_text">  <text>	 <xsl:apply-templates/>  </text></xsl:template>

and then where you had your previous code you could simply use

<xsl:apply-templates select="./../Order_Text[@Key=$textversion]/ad_database_text"/>

That's all guessing on to what you want to achieve, you might want to show us an XML input sample and the corresponding output sample, then we can suggest an XSLT solution.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...