Using XSLT 2.0:
@ Linenumber 8370 this code:
<TestCaseElement>
<Name><![CDATA[DUT_AC_ON]]></Name>
<TaggedValues>
</TaggedValues>
<Description>
<Line><![CDATA[{TEXT_LANG} DUT AC ON]]></Line>
<Line><![CDATA[{TEXT_ENGL} DUT AC ON]]></Line>
</Description>
<ModelingToolID><![CDATA[EAID_E9ACC0C9_D383_4ef0_99FF_F87C90BDF43C]]></ModelingToolID>
<Hash><![CDATA[1238228468]]></Hash>
<ID><![CDATA[1115]]></ID>
<Stereotypes>
<Stereotype><![CDATA[StepStart]]></Stereotype>
</Stereotypes>
<Role><![CDATA[TESTSTEP]]></Role>
</TestCaseElement>
and later in the XML-Document the same ModelingToolID
Here is an external Link to the picture to visualize: https://i.stack.imgur.com/vOFNz.png
I generate ID’s with this XSL-Code:
<xsl:for-each select="/TestCases/TestCase/TestCaseElement/ModelingToolID[
( not( ../Stereotypes ) or ( ../Stereotypes/Stereotype != 'Precondition' and
../Stereotypes/Stereotype != 'Postcondition' ) ) and
(../Stereotypes/Stereotype = 'StepStart') and
( ../Role = 'TESTSTEP' or ../Role = 'VP' ) and
../Description and
( generate-id() = generate-id( key( 'ModelingToolID', .)[ 1 ] ) ) ]">
You see in Linenumber 8370 and 10296 two identic ModelingToolID’s.
I need both TestCaseElements in my Transformation and in my desired output.
But, understandably, only the first will be taken.
What can i do to get both TestCaseElement’s?
The function
key()(without a predicate appended to it) by definition produces a node-set of nodes, each having the same key as the second argument.Therefore, inside the
xsl:for-eachinstruction you need:This selects all nodes that match the match pattern in the
matchattribute of thexsl:keynamed"ModelingToolID"— exactly what you want to obtain.You can use this expression in various XSLT instructions:
Or:
Or whatever you need to do.