on 10-08-2009 3:35 AM
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"?>
<xsl:stylesheet version="1.0" xmlns:xsl="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"?>
<PORR xmlns:fo="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
Hi,
I am not sure why your XSLT behaving like that,please try this XSL,what i did chnages is Templete match /*,I given exact path in Value of select,.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/*">
<PORR>
<Name><xsl:value-of select="/Source/Surname/Details"/></Name>
</PORR>
</xsl:template>
</xsl:stylesheet>
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
thank you very much for your advice. Yes, I have also tried to use the root element in the template match. It works, however the problem is that I have a lot of sub-fields in my real message, and I wanted to avoid typing the whole path each time. This is the reason why I wanted to use template-match to point directly to the parent node so that i just have to name the child element name (without path) in the select statemt.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.