[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Putting characters in an element

Subject: Putting characters in an element
From: Harm Kok <h.kok@xxxxxxxxxxxxxxx>
Date: Thu, 02 Oct 2003 14:47:54 +0200
regular expression in xslt1.0
Hi,

I am having the following problem. I would like to put a list number in a seperate element and preserve the other in-line elements.

input:
<?xml version="1.0"?>
<root>
<al>1. This is some very <emphasis>important</emphasis> tekst.</al>
<al>2. And a second line</al>
<al>And a last line</al>
</root>

desired output:
<li><li.nr>1.</li.nr><al>This is some very <emphasis>important</emphasis> tekst.</al></li>
<li><li.nr>2.</li.nr><al>And a second line</al></li>
<al>And a last line</al>


I can use XSLT 2 for the solution, but even with this I have not been able to solve the problem.
I have tried the following solution. It works perfectly with strings, but the inline element <emphasis> is not copied to the output.


Stylesheet:
<xsl:template match="al">
   <xsl:param name="first-string">
       <xsl:value-of select="substring-before(., ' ')"/>
   </xsl:param>

   <xsl:choose>
   <xsl:when test="matches($first-string,'\d')">
       <li>
           <xsl:analyze-string select="." regex="^\d\. ">
             <xsl:matching-substring>
               <nr><xsl:value-of select="."/></nr>
             </xsl:matching-substring>
             <xsl:non-matching-substring>
               <al><xsl:copy-of select="."/>
               </al>
             </xsl:non-matching-substring>
           </xsl:analyze-string>
       </li>
   </xsl:when>
   <xsl:otherwise>
       <al><xsl:copy-of select="descendant::node()"/></al>
   </xsl:otherwise>
   </xsl:choose>
</xsl:template>

How can I achieve this without nodes in stead of strings (in XSLT1.0 or XSLT2.0)?

Regards,

Harm




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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.