This content has been marked as final. Show 4 replies
Don't really understand what you want to do,
but this will concatenate the text in the elements
and store it in a 'target' variable:
<xsl:apply-templates select="animal" mode="text"/>
<xsl:template match="animal" mode="text">
I have a translation in BPEL where the source schema can contain a number of strings, but the target schema needs these in one field. I think it is some kind of comments.
Everything takes place in one giant transformation so it needs to be done within one match. I have tried with for-each but have not been able to get it working.
OK I got it working.
It works but please let me know if there is a better solution.
<xsl:variable name="f_191_1_dummy"> <xsl:for-each select="/tns1:hentNesteIndberetningResponse/tns1:hentNesteIndberetningReturn/tns1:Report/ns8:FertilizerAccountStructure/ns8:ConsumptionNitrogenStructure/ns8:OrganicFertilizerExceptManureStructure/ns8:FertilizerQuantitiesIncludedInAccountStructure/ns8:FertilizerQuantityCollection/ns8:FertilizerQuantityStructure/ns8:UnclassifiedFertilizer[../ns8:UnclassifiedFertilizer != '']"> <xsl:value-of select="concat(normalize-space(./text()),' ')"/> </xsl:for-each> </xsl:variable> <ns0:F_191_1> <xsl:value-of select="substring($f_191_1_dummy,1,255)"/> </ns0:F_191_1>
If it works, don't touch it !
I prefer using the functional programming style with apply-templates and match,
rather than the imperative call-template or for-each, it is closer to the Zen of XSLT.
Just as structured programming is about getting rid of the goto,
and OO polymorphism is about getting rid of the switch/case statement,
so functional programming is about pattern matching not iteration and invocation.
Note how you can use modes to distinguish between multiple templates
that match on the same pattern. In the example above, adding the template
for animal with mode='text' does not interfere with any other animal template.
The mode names are arbitrary, there is nothing special about 'text' in this context,
I could have used mode='Zen'.