My XSL tranform takes the data below, and generates xml output, which is effectively marked-up 'text'. The text-wrapping mark-up in the output is abbreviated to <aaa>. For simplicity within my transform, I have defined these marked-up data as variables.
I effectively want simulate the concat( , ) function (which works only for xs:string) but preserve the mark-up as well. My output should look something like:
$open $data1 $comma $data2 $comma $data3 $close; i.e.
HOWEVER, the difficulty is that I cannot guarentee that data1, data2 or data3 exists. Thus I need to test each 'piece' of data for existance and whether or not it is first or last (these come with parantheses).
Something along the lines of (in pseudo-code):
CHOOSE
WHEN(first and last)
$open $dataX $close
WHEN(first)
$open $dataX
WHEN(last)
$dataX $close
OTHERWISE
$dataX $comma
/CHOOSE
For a similar solution, dealing with only xs:string please see this post
I effectively want simulate the concat( , ) function (which works only for xs:string) but preserve the mark-up as well. My output should look something like:
$open $data1 $comma $data2 $comma $data3 $close; i.e.
Code:
OUTPUT STRUCTURE
<aaa>(</aaa>
<aaa>1.11</aaa>
<aaa>g</aaa>
<aaa>, </aaa>
<aaa>2.22</aaa>
<aaa>mol</aaa>
..... etc.
HOWEVER, the difficulty is that I cannot guarentee that data1, data2 or data3 exists. Thus I need to test each 'piece' of data for existance and whether or not it is first or last (these come with parantheses).
Something along the lines of (in pseudo-code):
CHOOSE
WHEN(first and last)
$open $dataX $close
WHEN(first)
$open $dataX
WHEN(last)
$dataX $close
OTHERWISE
$dataX $comma
/CHOOSE
For a similar solution, dealing with only xs:string please see this post
Code:
INPUT STRUCTURE
<data>
<data1 unit="g">1.11</data1>
<data2 unit="mol">2.22</data2>
<data3 unit="percent">3.33</data3>
</data>
Code:
DECLARED VARIABLES IN TEMPLATE
$data1 = "<aaa>1.11</aaa><aaa>g</aaa>
$data2 = "<aaa>2.22</aaa><aaa>mol</aaa>
$data3 = "<aaa>3.33</aaa><aaa> %</aaa>
$open = "<aaa>(</aaa>"
$close = "<aaa>, </aaa>"
$comma = "<aaa>)</aaa>"