Simple parent value xsl question

R

readytohelp

I have the following XML
<root>
<Companies>
<Name>Labs</Name>
<display>Labs </display>
<val>1</val>
<Products>
<val>1</val>
<display>Maxa</display>
<CompanyKey>1</CompanyKey>
<Topics>
<val>3</val>
<display>Psychological</display>
<CompanyKey>1</CompanyKey>
<product>1</product>
</Topics>
<Topics>
<val>5</val>
<display>Finance</display>
<CompanyKey>1</CompanyKey>
<product>1</product>
</Topics>

And the following XSL

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="listboxname" />
<xsl:param name="mainTable" />
<xsl:param name="subTable" />

<xsl:template match="/">
<xsl:call-template name="main" >
<xsl:with-param name="nodes" select="child::node()"/>
</xsl:call-template>

</xsl:template>

<xsl:template name="main">
<xsl:param name="nodes"/>
<xsl:for-each select="$nodes">
<xsl:value-of select="parent::val"/>
<xsl:if test="val">
<xsl:value-of select="concat(val,'-')" />
</xsl:if>
<xsl:if test="display">
<xsl:value-of select="concat(display,'*')" />
</xsl:if>
<xsl:call-template name="main">
<xsl:with-param name="nodes" select="child::node()"/>
</xsl:call-template>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

The output is:

1-Labs *11-Maxa*13-Psychological*35-Finance*56-Managed Care (MSMs
Representative Only)*62-Namenda*22-Alzheimer's
Disease*23C8B03C9-44A0-4C9B-82E1-B2CD95FDC13A-Long-Term
Care*3C8B03C9-44A0-4C9B-82E1-B2CD95FDC13A652089A7-E8BC-42AB-BC75-833280A
B65AF-Managed
Care*652089A7-E8BC-42AB-BC75-833280AB65AF

For <xsl:value-of select="parent::val"/>
Why does it not print the val of the parent.
For e.g. for Finance it should print 1 (val of Products) why is is
printing 3, which is the val of Psychological
 
J

Joris Gillis

For said:
Why does it not print the val of the parent.
For e.g. for Finance it should print 1 (val of Products) why is is
printing 3, which is the val of Psychological
Hi,

Because the Xpath expression 'parent::val' selects a parent that is called 'val', it does not select the 'val' child of the parent or anything like that.
Either use:
<xsl:value-of select="parent::*/child::val"/>
or <xsl:value-of select="../val"/>

Btw, are those named-templates and with-params really neccesary?

regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,998
Messages
2,570,242
Members
46,834
Latest member
vina0631

Latest Threads

Top