Re: [xsl] String extraction

Subject: Re: [xsl] String extraction
From: Sven Waibel <sven.waibel@xxxxxxxx>
Date: Thu, 30 Sep 2004 16:27:30 +0200
Hi Mukul,

thanks a lot, excellent work!

Sven

Mukul Gandhi wrote:

> Hi Sven,
>   Please try this XSL -
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> 
> <xsl:output method="html" indent="yes"/>
> 	
> <xsl:template match="/top">
>   <xsl:variable name="str1"
> select="substring-before(., '(')"/>
>   <xsl:variable name="str2">
>     <xsl:choose>
>       <xsl:when test="contains(substring-after(.,
> '('), ',')">
>         <xsl:value-of
> select="substring-before(substring-after(., '('),
> ',')"/>
>       </xsl:when>
>       <xsl:otherwise>
> 	<xsl:value-of
> select="substring-before(substring-after(., '('),
> ')')"/>
>       </xsl:otherwise>
>     </xsl:choose>
>    </xsl:variable>
>    <xsl:variable name="str3"
> select="substring-before(substring-after(., ','),
> ')')"/>		
>    <html>
>      <head>
>        <title/>
>      </head>
>      <body>
>        <table>
> 	 <tr>
> 	   <td>
> 	     <xsl:value-of select="$str1"/>
> 	   </td>
> 	   <td>
> 	     <xsl:value-of select="$str2"/>
> 	   </td>
> 	 </tr>
> 	 <xsl:call-template name="generateTRs">
> 	   <xsl:with-param name="str" select="$str3"/>
> 	   <xsl:with-param name="delim" select="','"/>
> 	 </xsl:call-template>
>        </table>
>      </body>
>    </html>
> </xsl:template>
> 	
> <!-- a recursive template to generate <tr>s -->
> <xsl:template name="generateTRs">
>   <xsl:param name="str"/>
>   <xsl:param name="delim"/>
>   
>   <xsl:choose>
>     <xsl:when test="contains($str, ',')">
>       <tr>
>        <td/>
>        <td>
> 	 <xsl:value-of select="substring-before($str, ',')"/>
>        </td>
>       </tr>
>       <xsl:call-template name="generateTRs">
> 	<xsl:with-param name="str"
> select="substring-after($str, ',')"/>
> 	<xsl:with-param name="delim" select="$delim"/>
>       </xsl:call-template>
>     </xsl:when>
>     <xsl:otherwise>
>       <tr>
> 	<td/>
> 	<td>
> 	  <xsl:value-of select="$str"/>
> 	</td>
>       </tr>
>     </xsl:otherwise>
>   </xsl:choose>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> Regards,
> Mukul
> 
> --- Sven Waibel <sven.waibel@xxxxxxxx> wrote:
> 
> 
>>Hi Mukul,
>>
>>that's a very good example, but i don't know how
>>many p exist. So i don't know how many variables i
>>have to create.
>>
>>Sven
>>
>>Mukul Gandhi wrote:
>>
>>
>>>Hi Sven,
>>>  Please try this XSL -
>>>
>>><?xml version="1.0" encoding="UTF-8"?>
>>><xsl:stylesheet version="1.0"
>>>xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>>><xsl:output method="html" indent="yes"/>
>>>	
>>><xsl:template match="/top">
>>>  <xsl:variable name="str1"
>>>select="substring-before(., '(')"/>
>>>  <xsl:variable name="str2"
>>>select="substring-before(substring-after(., '('),
>>>',')"/>
>>>  <xsl:variable name="str3"
>>>
>>
> select="substring-before(substring-after(substring-after(.,
> 
>>>'('), ','), ',')"/>
>>>  <xsl:variable name="str4"
>>>
>>
> select="substring-before(substring-after(substring-after(substring-after(.,
> 
>>>'('), ','), ','), ')')"/>
>>>  <html>
>>>    <head>
>>>      <title/>
>>>    </head>
>>>    <body>
>>>      <table>
>>>	<tr>
>>>	 <td><xsl:value-of select="$str1" /></td>
>>>	 <td><xsl:value-of select="$str2" /></td>
>>>	</tr>
>>>	<tr>
>>>	 <td/>
>>>	 <td><xsl:value-of select="$str3" /></td>
>>>	</tr>
>>>	<tr>
>>>	 <td/>
>>>	 <td><xsl:value-of select="$str4" /></td>
>>>	</tr>
>>>      </table>
>>>    </body>
>>>  </html>
>>></xsl:template>
>>>	
>>></xsl:stylesheet>
>>>
>>>When the above XSL is applied to XML -
>>>
>>><?xml version="1.0" encoding="UTF-8"?>
>>><top>person(p1,p2,p3)</top>
>>>
>>>it produces the desired output.
>>>
>>>Regards,
>>>Mukul
>>>
>>>--- Sven Waibel <sven.waibel@xxxxxxxx> wrote:
>>>
>>>
>>>
>>>>Hello,
>>>>
>>>>how can i extract a string from a string:
>>>>
>>>>person(p1,p2,p3)
>>>>
>>>>I need a table:
>>>>
>>>>person p1
>>>>	 p2
>>>>	 p3
>>>>
>>>>I don't know anything about length of p1,p2 or p3.
>>>>
>>>>Is is possible?
>>>>
>>>>Regards
>>>>Sven
> 
> 
> 
> 		
> _______________________________
> Do you Yahoo!?
> Declare Yourself - Register online to vote today!
> http://vote.yahoo.com

Current Thread