Jump to content

Xsl:if Relation Problem


Loriot
 Share

Recommended Posts

Hi,I have a source xml that looks like that

<tabell navn="A"> <liste> <data navn="kode">A</data> <tabell navn="same"> <liste> <data navn="Navn">Jens</data> <data navn="Navn">Inge</data> </liste> </tabell> </liste> <liste> <data navn="kode">B</data> <tabell navn="same"> <liste> <data navn="Navn">Anna</data> <data navn="Navn">Peter</data> </liste> </tabell> </liste> </tabell>
I want a result that shows only the names of the list following the kode A. Like that
<result><navn>Jens</navn><navn>Inge</navn></result>
My stylesheet looks like that
<result><xsl:for-each select="tabell/liste"><xsl:if test="data[@navn=kode]='A'"><xsl:for-each select="following::tabell/liste"><navn><xsl:value-of select="data[@navn=navn]"/></navn></xsl:for-each></xsl:if></xsl:for-each></result>
I tried a couple of different variations with this name followers but do not manage to figure it out how this should belong together and the result is always empty. Hope anyone can help.
Link to comment
Share on other sites

there are several ways to do this. heres one:

			<xsl:template match="/">				<result>					<xsl:for-each select="//data[@navn='Navn'][ancestor::liste/data[@navn='kode']='A']">						<navn><xsl:value-of select="."/></navn>					</xsl:for-each>				</result>			</xsl:template>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...