xml - Search values without repeating value of the first parameter -
i'm using xsl 1.0 respective values of each parameter xml below. notes below current results of second parameter value of first repeating. use function choose not find value = 'null'
my xml:
<individuo param='1' > <data> <f16> <row f1='breast' f2='63'/> </f16> </individuo> <individuo param='2' > <data> <f16> <row f1='beddle' f2='40'/> </f16> </individuo>
my xsl code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:rdf="http://xxx#" version="1.0"> <xsl:strip-space elements="*"/> <xsl:output method="xml" indent="yes"/> <!-- begin rdf document --> <xsl:template match="/"> <xsl:element name="rdf:rdf"> <rdf:description rdf:about="http://xxx"> <xsl:apply-templates/> </rdf:description> </xsl:element> </xsl:template> <xsl:template match="f16"> <xsl:choose> <xsl:when test="/individuo/data/f16/row/@f1 !='null'"> <xsl:element name="hasnamecancer" namespace="{namespace-uri()}#"> <xsl:value-of select="/individuo/data/f16/row/@f1" /> </xsl:element> </xsl:when> </xsl:choose> <xsl:choose> <xsl:when test="/individuo/data/f16/row/@f2 !='null'"> <xsl:element name="idadediag" namespace="{namespace-uri()}#"> <xsl:value-of select="/individuo/data/f16/row/@f2" /> </xsl:element> </xsl:when> </xsl:choose>
my actual result:
<individuo_1> <hasnamecancer>breast</hasnamecancer> <idadediag>63</idadediag> </individuo_1> <individuo_2> <hasnamecancer>breast</hasnamecancer> <idadediag>63</idadediag> </individuo_2>
i wish result be:
<individuo_1> <hasnamecancer>breast</hasnamecancer> <idadediag>63</idadediag> </individuo_1> <individuo_2> <hasnamecancer>beddle</hasnamecancer> <idadediag>40</idadediag> </individuo_2>
you getting same results because not selecting rows in context of f16
. getting first element because selecting collection of all rows. since context f16
can select descendant nodes using relative expressions.
to select element in context, use relative xpath expressions in test
, select
:
<xsl:template match="f16"> <xsl:choose> <xsl:when test="row/@f1"> <xsl:element name="hasnamecancer" namespace="{namespace-uri()}#"> <xsl:value-of select="row/@f1" /> </xsl:element> </xsl:when> </xsl:choose> ...
Comments
Post a Comment