Reputation: 5019
I have a piece of xslt file which looks like this:
<xsl:template match="Request">
<Instrument>
<IdentifierType>
<xsl:value-of select="IDContext"/>
</IdentifierType>
<Identifier>
<xsl:value-of select="Identifier"/>
</Identifier>
<UserDefinedIdentifier>
<xsl:value-of select="UserDefinedIdentifier"/>
</UserDefinedIdentifier>
<xsl:if test="Param[@Key='Exchange']">
<Exchange>
<xsl:value-of select="Param[@Key='Exchange']"/>
</Exchange>
</xsl:if>
</Instrument>
</xsl:template>
And one input xml piece look like this:
<Request>
<Identifier>XXX</Identifier>
<IDContext>ISIN</IDContext>
</Request>
Now I want to modify the input xml a little bit, so that the output would be like this:
<Instrument>
<IdentifierType>ISIN</IdentifierType>
<Identifier>XXX</Identifier>
<Exchange>EX</Exchange>
</Instrument>
How should I modify the input xml file? Thank you!
Upvotes: 1
Views: 30
Reputation: 70648
The XSLT is currently looking for a Param
element that is a child of the current Request
element that is being matched. This means you would expect your XML to look like this:
<Request>
<Identifier>XXX</Identifier>
<IDContext>ISIN</IDContext>
<Param Key='Exchange'>EX</Param>
</Request>
Having said that, this generates the following output:
<Instrument>
<IdentifierType>ISIN</IdentifierType>
<Identifier>XXX</Identifier>
<UserDefinedIdentifier/>
<Exchange>EX</Exchange>
</Instrument>
The template you have shown always creates a UserDefinedIdentifier
for the Request
element, regardless of whether a UserDefinedIdentifier
element exists in the XML or not. The only way around this would be to change the XSLT to handle one not being present.
Upvotes: 2