This seems simple enough but I can't seem to get it to work.
My xml looks like this:
HTML Code:
<bsar:BSAForm>
<bsar:SubjectInformation>
<bsar:LastNameOrNameOfEntity> Obama</bsar:LastNameOrNameOfEntity>
<bsar:AddressBlock>
<ucc:Address> 9 Dale Rd</ucc:Address>
<ucc:City> Woodbury</ucc:City>
</bsar:AddressBlock>
<bsar:AddressBlock>
<ucc:Address> 123 Fake St</ucc:Address>
<ucc:City> Springfield</ucc:City>
</bsar:AddressBlock>
</bsar:SubjectInformation>
</bsar:BSAForm>
I need to iterate over both of these elements and display the content. My XSLT looks like this:
HTML Code:
<xsl:template match=/bsar:BSAForm">
<xsl:apply-templates select="bsar:SubjectInformation"/>
</xsl:template>
<xsl:template match="bsar:SubjectInformation">
<xsl:text xml:space="preserve">4A</xsl:text>
<xsl:text xml:space="preserve">00001</xsl:text>
<xsl:value-of select="bsar:LastNameOrNameOfEntity"/>
<xsl:value-of select="'
'"/> <!-- new line -->
<xsl:apply-templates select="bsar:AddressBlock"/>
</xsl:template>
<xsl:template match="bsar:AddressBlock">
<xsl:variable name="Addr" select="../bsar:AddressBlock"/>
<xsl:text xml:space="preserve">4B</xsl:text>
<xsl:text xml:space="preserve">00001</xsl:text>
<xsl:value-of select="$Addr/ucc:Address"/>
<xsl:value-of select="$Addr/ucc:City"/>
<xsl:value-of select="'
'"/> <!-- new line -->
</xsl:template>
The output should be as follows:
Code:
4A 00001 Obama
4B 9 Dale Rd Woodbury
4B 123 Fake St Springfield
But instead, the output is coming out like this:
Code:
4A 00001 Obama
4B 9 Dale Rd Woodbury
4B 9 Dale Rd Woodbury
I have tried many different ways to do this, using a for each, using a for each like this:
HTML Code:
<xsl:variable name="header" select="."/>
<xsl:for-each select="following-sibling::bsar:TelephoneBlock[ancestor::bsar:SubjectInformation[1] = $header]">
or even passing in a counter from a for-loop and using that to access the specified element like this:
HTML Code:
<xsl:for-each select="bsar:TelephoneBlock">
<xsl:variable name="Index">
<xsl:number count="bsar:TelephoneBlock" />
</xsl:variable>
<xsl:call-template name="SubjectPhone">
<xsl:with-param name="$Index"/>
</xsl:call-template>
</xsl:for-each>
<xsl:template name="SubjectPhone">
<xsl:param name="Index"/>
<xsl:variable name="Telephone" select="../bsar:TelephoneBlock[$Index]"/>
...
</xsl:template>
In all these cases, it's displaying the first address twice. Pleae let me know if you notice anything I am doing wrong.
Thanks in advance.