2012-04-28 14 views
2

XSLでXSLファイルを解析しています。私はそれにノードを動的に見つける問題があります。XSL:ノードを動的に選択

<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> 

私はlabelArc要素を解析し、loc要素からの情報を含めるようにしたいのです:ここではシナリオです。これは、次のように私のXSLコードが見えます... SAP/ABAPで

が行われます。

<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> 

私は出力にlocタグから@hrefを含めたいです。対応するlocタグの値は@toで、それぞれlabelArcタグです。

私の問題は、この文は、空の値を返すということです。

<xsl:value-of select="//lb:loc[@label='$arc_to']/@href"/> 

私がリードする名前空間の両方を試してみました「のxlink:」各属性にし、それなしで...

任意のアイデア?

答えて

3

あなたのコードには2つの問題があります。まず

<xsl:variable name="arc_to"  
     select="@xlink:to"/> 

は通知を行いますが、その文字列"label_"labelArc開始のxlink:toの価値 - とxlink:label属性locの文字列はこの文字列で始まりません。第二に

<xsl:value-of select="//lb:loc[@xlink:label='$arc_to']/@xlink:href"/> 

これは文字列"$arc_to"@xlink:labelを比較して - いない変数$arc_toに。

修正コード:この変換が提供されるXML文書に適用される

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:lb="http://www.xbrl.org/2003/linkbase" 
xmlns:xlink="http://www.w3.org/1999/xlink" 
    exclude-result-prefixes="lb xlink"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="lb:labelArc"> 
    <xsl:variable name="arc_to" 
     select="substring-after(@xlink:to, 'label_')"/> 

    <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> 
</xsl:stylesheet> 

:希望、正しい結果が生成さ

<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 priority="1" xlink:type="arc" 
    xlink:from="de-gaap-ci_bs.ass.fixAss.fin.otherLoans.other" 
    xlink:to="label_de-gaap-ci_bs.ass.fixAss.fin.otherLoans.other" 
    xlink:arcrole="http://www.xbrl.org/2003/arcrole/concept-label" /> 

      <!-- many <labelArc... elements --> 

</labelLink> 
</linkbase> 

<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> 
+0

不足している「label_」の間違いを指摘してくれてありがとう!あなたは私が以前認識していなかった私の別の問題を暗黙に解決しました:-) –

+0

@MarcoNätlitz:あなたは大歓迎です。 –

1

試してみてください。

<xsl:value-of select="//lb:loc[@label=$arc_to]/@href"/> 

あなたは

<xsl:value-of select="//lb:loc[@label='$arc_to']/@href"/> 

を記述する場合、あなたが文字列「$のarc_to」ではなくarc_to変数の値に対して一致するXSLプロセッサを伝えます。

関連する問題