|
Subject: Fw: [xsl] function returning string with string-join() From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx> Date: Fri, 6 Aug 2010 12:30:07 +0200 |
As a side note this can even be done with just XPATH 1.0:
$ xpath++ "concat(substring('NoXNo1No2',1+string-length(concat(*[/ = 1],*[/
= 2],*[/ = 2]))*3,3),'.html')" 3.xml
NoX.html
$ xpath++ "concat(substring('NoXNo1No2',1+string-length(concat(*[/ = 1],*[/
= 2],*[/ = 2]))*3,3),'.html')" 2.xml
No2.html
$ cat 3.xml
<xml>3</xml>
$
xpath++ tool is based on xsltproc or DataPower processor:
https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14488694#1448
8694
Mit besten Gruessen / Best wishes,
Hermann Stamm-Wilbrandt
Developer, XML Compiler, L3
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
----- Forwarded by Hermann Stamm-Wilbrandt/Germany/IBM on 08/06/2010 12:24
PM -----
From: Hermann Stamm-Wilbrandt/Germany/IBM@IBMDE
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Date: 08/06/2010 11:22 AM
Subject: Re: [xsl] function returning string with string-join()
<xsl:template match="/">
<xsl:value-of select="string-join((if (* = 1) then 'NO1' else if (* = 2)
then 'NO2' else 'NOx','.html'),'')"/>
</xsl:template>
Mit besten Gruessen / Best wishes,
Hermann Stamm-Wilbrandt
Developer, XML Compiler, L3
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
From: Michael M|ller-Hillebrand <mmh@xxxxxxxxxxxxx>
To: XSL-List <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
Date: 08/06/2010 10:59 AM
Subject: [xsl] function returning string with string-join()
Hello experts,
I find myself building functions like this (no real code!) to return a
string:
<xsl:function name="my:filename" as="xs:string">
<xsl:param name="input" as="xs:integer" />
<xsl:variable name="strings">
<xsl:choose>
<xsl:when test="$input eq 1">
<xsl:value-of select="'NO1'" />
</xsl:when>
<xsl:when test="$input eq 2">
<xsl:value-of select="'NO2'" />
</xsl:when>
<xsl:otherwise>
<xsl:message select="'otherwise?'" />
<xsl:value-of select="'NOx'" />
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="'.html'" />
</xsl:variable>
<xsl:value-of select="string-join($strings, '')" />
</xsl:function>
In a variable this builds a sequence of strings using individual
xsl:value-of and in the end they are joined. Is this the way to do it if I
cannot concat() everything in a single, large xsl:value-of?
I have a feeling that it might be simpler?
Thanks for teaching me new/old tricks :-)
- Michael
--
_______________________________________________________________
Michael M|ller-Hillebrand: Dokumentation Technology
Adobe Certified Expert, FrameMaker
Consulting and Training, FrameScript, XML/XSL, Unicode
Blog [de]: http://cap-studio.de/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] function returning string, Michael Kay | Thread | [xsl] Katakana substitution regex, Hoskins & Gretton |
| Re: [xsl] function returning string, Hermann Stamm-Wilbra | Date | Re: [xsl] function returning string, Michael Müller-Hille |
| Month |