Skip to Content
0
Former Member
Oct 08, 2009 at 02:35 AM

Strange XSLT Behavior: xsl:template match

13 Views

Hello I found the following strange XSLT behavior when using xsl:template. I only want to read the content of the element /Source/Surname/Details. Therefore I match this path using xsl:template match.

What is strange that in the target message also the value of the Element LastName is written at the end. Please see example below. This is just a short example to point out the problem. I have a bigger message structure where I have to match a similar path. How can I avoid the the value of the FullDetails is just written at the end (not even beeing in an element)? I would have expected that the path is only matched once and the instructions then executed without <LastName> beeing even touched.I used XML Spy for this test.

Here is an example:

Source message:

<?xml version="1.0" encoding="UTF-8"?>

<Source>

<Surname>

<Details>MyFirstName</Details>

</Surname>

<LastName>

<FullDetails> MyLastName </FullDetails>

</LastName>

</Source>

XSLT

<?xml version="1.0" encoding="UTF-8"?>

http://www.w3.org/1999/XSL/Transform" xmlns:fo=" http://www.w3.org/1999/XSL/Format">

<xsl:template match="/Source/Surname">

<PORR>

<Name><xsl:value-of select="Details"/></Name>

</PORR>

</xsl:template>

</xsl:stylesheet>

Target Message

<?xml version="1.0" encoding="UTF-8"?>

http://www.w3.org/1999/XSL/Format">

<Name>MyFirstName</Name></PORR>MyLastName

Edited by: Florian Guppenberger on Oct 8, 2009 4:35 AM

Edited by: Florian Guppenberger on Oct 8, 2009 4:36 AM

Edited by: Florian Guppenberger on Oct 8, 2009 4:36 AM

Edited by: Florian Guppenberger on Oct 8, 2009 4:37 AM