taffmeister Posted July 1, 2010 Share Posted July 1, 2010 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 More sharing options...
boen_robot Posted July 1, 2010 Share Posted July 1, 2010 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 More sharing options...
Martin Honnen Posted July 1, 2010 Share Posted July 1, 2010 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 More sharing options...
taffmeister Posted July 5, 2010 Author Share Posted July 5, 2010 Hi,thanks for the examples you sent over it's much appreciated.Unfortunately neither seem to work when I put them within my code.Nathan Link to comment Share on other sites More sharing options...
Martin Honnen Posted July 5, 2010 Share Posted July 5, 2010 Consider to post minimal but complete samples to demonstrate the problem (.i.e. an input sample, a stylesheet sample, the output you get, the output you want) then we can certainly help you. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.