Search with criteria for value in different XML node in an XSLT Template

There have been a few instances where I have had to filter the incoming XML to look for a value from a different node in the XML. For the example in this article I had the parent node id but I wanted to know the name of that parent node.

This excellent article gave me a starting point for the principle of searching for values in different nodes using an XSLT template. This worked spendedly in one map I was working where I was trying to sum up all values in the current list of node items.

<xsl:template name="OutputSum">
  <xsl:param name="param1" />
  <xsl:element name="TransactionAmount">
    <xsl:variable name="var:vTranAmt"
    select="sum(//ExpenseItem[ReportEntryID=$param1]/TransactionAdjustmentAmount" />

    <xsl:value-of select="$var:vTranAmt" />


However, when I tried to use the same principle to select the name value of a parent node for which I only knew the ID, it just wouldn’t work. I kept gettiing blank values no matter what I tried.

The source schema was from the MS Dynamics CRM v4 web services using the RetrieveMultiple method and is much more complex than one I normally use. After a lot of headscratching I noticed that it was the namespaces that were causing the problems. When I right clicked the map, selected validate and viewed the .xsl that Visual Studio was generating I noticed in my other mappings that BizTalk was adding some bizarre namespaces to the nodes, e.g. s6:RetrieveMultipleResult/s4:BusinessEntities . Eventually I got it to work using these namespaces.

<xsl:template name="ParentCompanyCode">
  <xsl:param name="param1" />
  <xsl:element name="Code">

                <xsl:value-of select="//s4:BusinessEntity[s6:new_geographyid=$param1]/s6:new_name" />


Unfortunately I can’t explain exactly why this was required, but my advise is that if you can’t work out why custom xsl isn’t working then create something similar using functoids and have a look through the xsl that it generates via the Validate map functionality.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>