I am parsing an XSL file with XSL. And I have a problem dynamically finding nodes in it. Here is the scenario:
<linkbase xmlns="http://www.xbrl.org/2003/linkbase"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.xbrl.org/2003/linkbase http://www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd">
<labelLink xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:role="http://www.xbrl.org/2003/role/link"
xlink:type="extended">
<loc xlink:type="locator"
xlink:href="de-gaap-ci-2010-12-16.xsd#de-gaap-ci_bs.ass.fixAss.fin.otherLoans.other"
xlink:label="de-gaap-ci_bs.ass.fixAss.fin.otherLoans.other"/>
<!-- many <loc... elements -->
<labelArc xlink:from="de-gaap-ci_bs.ass.fixAss.fin.otherLoans.other"
xlink:to="label_de-gaap-ci_bs.ass.fixAss.fin.otherLoans.other"
priority="1"
xlink:arcrole="http://www.xbrl.org/2003/arcrole/concept-label"
xlink:type="arc"/>
<!-- many <labelArc... elements -->
</labelLink>
</linkbase>
I am parsing the labelArc elements and want to include the information from the loc elements. This is done with SAP/ABAP…
My XSL code looks as follows:
<xsl:stylesheet version="1.0"
xmlns:lb="http://www.xbrl.org/2003/linkbase"
xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:template match="lb:labelArc">
<xsl:variable name="arc_to" select="@xlink:to"/>
<TY_T_LABELARC>
<LOC> <xsl:value-of select="//lb:loc[@xlink:label='$arc_to']/@xlink:href"/> </LOC>
<FROM> <xsl:value-of select="@xlink:from"/> </FROM>
<TO> <xsl:value-of select="@xlink:to"/> </TO>
<!-- Other values follow -->
</TY_T_LABELARC>
</xsl:template>
I expect this result:
<TY_T_LABELARC>
<LOC>de-gaap-ci-2010-12-16.xsd#de-gaap-ci_bs.ass.fixAss.fin.otherLoans.other</LOC>
<FROM>de-gaap-ci_bs.ass.fixAss.fin.otherLoans.other</FROM>
<TO>label_de-gaap-ci_bs.ass.fixAss.fin.otherLoans.other</TO>
</TY_T_LABELARC>
My problem is that it’s all okay except the element LOC which has an empty value (<LOC/>).
It means this xpath expression returns an empty value:
<xsl:value-of select="//lb:loc[@label='$arc_to']/@href"/>
The goal of this statement is to get the attribute href from the element loc. I can find the corresponding loc tag with the value of @to of each labelArc tag.
I tried it both with the leading namespace “xlink:” on each attribute and without it…
Any ideas?
There are two issues with your code:
Firstly:
Do notice that the value of the attribute
xlink:toof the elementlabelArcstarts with the string"label_"— and thexlink:labelattribute oflocdoesn’t start with this string.So you should write:
Secondly:
this compares
@xlink:labelto the string"$arc_to"— not to the variable$arc_to.So you should write:
The corrected code:
when this transformation is applied to the provided XML document:
the wanted, correct result is produced: