python - XSLT select from a nested element -
i'm sure i'm missing simple here...
i can't select nested xml element using xlst transform.
here xml
<collection> <record> <leader>01814nam a2200205ia 4500</leader> <controlfield tag="003">psca</controlfield> <controlfield tag="005">20141201150951.0</controlfield> <controlfield tag="008">131110s9999 xx 000 0 und d</controlfield> <datafield tag="040" ind1=" " ind2=" "> <subfield code="a">psca</subfield> <subfield code="c">calyx</subfield> </datafield> <datafield tag="110" ind1=" " ind2=" "> <subfield code="9">76</subfield> <subfield code="a">children's services central</subfield> </datafield> <datafield tag="245" ind1="0" ind2="0"> <subfield code="a">what's pedagogy anyway?</subfield> <subfield code="b">using pedagogical documentation engage years learning framework </subfield> </datafield> </record> </collection
i need select following data:
/collection
/record
/datafield
-->/@tag='245'
---->/subfield/@code='a'
i expect output be: "what's pedagogy anyway?"
my xlst select node/data such:
<xsl:for-each select="collection/record/datafield"> <xsl:choose> <xsl:when test="@tag=245"> <xsl:choose> <xsl:when test="/subfeild/@code=a"> <xsl:value-of select="/subfeild"/> </xsl:when> </xsl:choose> </xsl:when> </xsl:choose> </xsl:for-each>
i'm running using lxml library in python if that's important. code compiles , runs without error. output null.
any ideas? in advance.
you might want change @code=a
@code='a'
, such as:
<xsl:template match="/"> <xsl:value-of select="collection/record/datafield[@tag=245]/subfield[@code='a']"/> </xsl:template>
edit
if insist on having for-each
loop, see below:
<xsl:template match="/"> <xsl:for-each select="collection/record/datafield"> <xsl:choose> <xsl:when test="@tag=245"> <xsl:value-of select="subfield[@code='a']"/> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:template>
Comments
Post a Comment