cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing multiple xml elements with same name

Former Member
0 Kudos

I am having trouble with an xsl stylesheet. This is what one of the rows of my output xml document looks like

<Row>

<Num>1</Num>

<Valuation>Val</Valuation>

<COMBCHARFLAG>Y</COMBCHARFLAG>

<CCCOUNT>2</CCCOUNT>

<CCDESC>CHARDESC1</CCDESC>

<CCDESC>CHARDESC2</CCDESC>

</Row>

Does anyone know how I can access the 2nd CCDESC ("CHARDESC2") . When i run this in the workbench I can only ever access the first CCDESC, it acts like the 2nd isn't there. However I was also using a 3rd party xsl editor called "XMLSpy" to look for other possible solutions and when i render it with XMLSpy, everything is displaying correctly. Is this some sort of limitation of the workbench? Any help would be much appreciated. Thanks

This is the template i am calling in my xsl.......

<xsl:template name="for.loop">

<xsl:param name="i" />

<xsl:param name="count" />

<!--begin_: Line_by_Line_Output -->

<xsl:if test="$i &lt;= $count">

<tr>

<td align="center"><xsl:value-of select="CCDESC[position()=$i]"/>

</td>

<td align="center">

<input style="width:110px;" class="Mfieldv-M" name="txtValuation"></input>

</td>

</tr>

</xsl:if>

<!begin_: RepeatTheLoopUntilFinished>

<xsl:if test="$i &lt;= $count">

<xsl:call-template name="for.loop">

<xsl:with-param name="i">

<xsl:value-of select="$i + 1"/>

</xsl:with-param>

<xsl:with-param name="count">

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

</xsl:with-param>

</xsl:call-template>

</xsl:if>

I than call the template as follows from within my <xsl:for-each select="Row"> statement

<xsl:call-template name="for.loop">

<xsl:with-param name="i">1</xsl:with-param>

<xsl:with-param name="count"><xsl:value-of select="CCCOUNT"/></xsl:with-param>

</xsl:call-template>

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Lucas,

If you just want to access only the second 'CCDESC' row, then use xPath as

Repeater_0.Output{/Row/CCDESC[2]}

If you want to call both the rows at the same time, then use 'for loop' action and iterate it to the number of similar type column count and use the xPath as

Repeater_0.Output{/Row/CCDESC[#ForNextRepeater_0.CurrentItem# + 1]}

to get the output

Hope this helps

Regards

Muzammil

Former Member
0 Kudos

Muzammil,

Thanks for the response. I may have explained my situation a little poorly. I am not trying to access the 2nd CCDESC within the workbench via a repeater or such. It is after the XSL renders the page that I don't see the second CCDESC. When the XSL renders the page through Internet explorer i get something that looks like the following......

Res # 1

CHARDESC1

When I render it in the application XMLSpy it shows both CCDESC's like follows.

Res # 1

CHARDESC1

CHARDESC2

In XMLSpy if i change the line of xsl code from <td align="center"><xsl:value-of select="CCDESC[position()=$i]"/> to <td align="center"><xsl:value-of select="CCDESC[2]"/> the page is rendered in XMLSpy with both labels the same as follows.

Res # 1

CHARDESC2

CHARDESC2

If i do that same change in the workbench and render the page through IE I get no label results....

Res # 1

Thanks

Former Member
0 Kudos

Lucas,

Try using

<xsl: for-each select="row/CCDESC">

instead of

<xsl:value-of select="CCDESC[2]"/> or <xsl:value-of select="CCDESCposition()=$i"/>

Hope this will work fine.

Regards

Muzammil

jcgood25
Active Contributor
0 Kudos

At face value your IllumDoc xml is invalid. Your column order and data item order in the rows are not in sync, and you cannot have a redundant u2018CCDESCu2019 column. The IllumDoc requires a complete format and when I test your XML in an XMLQuery template (even though it is valid xml) I only see 3 rows and 5 columns (the 6th column is stripped because it is redundant) and this would seemingly explain why you donu2019t see it when the xslt renders the html.

If you reconstruct the format of your XML you will probably get what you need. I always make the xslt work quite utilitarian, and avoid too much crazy xslt language. I find it a bit easier to formulate the xml file in such a way that I can spoon feed the xsl.