2017-05-06 8 views
0

xsltの変換に少し問題がありました... 私は思うが、私はインターネット上で解決策を見つけることはできません。 xmlノード内の番号または日付を選択しようとすると、他のXMLでは表示できません。これは元のコードである1.0XMLからXMLへのXSLT番号

私は、XSLTのバージョンを使用しています =:

<?xml version="1.0" encoding="utf-8"?> 
<ALL_Machines_having_buttons_from_a_Machintype_price_greater9700> 
    <GreaterTypes> 
     <typename>Grant and Sons</typename> 
     <price>984912.41</price> 
     <serialnumber>7</serialnumber> 
     <outputrate>5</outputrate> 
     <purchasebillxml> 
     <purchasebill> 
      <billnumber>345-20-2422</billnumber> 
      <seller> 
       <id>Nienow-Daugherty</id> 
      </seller> 
      <product> 
       <articlenumber>172185964-0</articlenumber> 
       <amount>50359</amount> 
       <price>676833.08</price> 
      </product> 
      <date>2004-01-28</date> 
     </purchasebill> 
     </purchasebillxml> 
     <buttonsname>595027529-2</buttonsname> 
     <colour>Khaki</colour> 
    </GreaterTypes> 
</ALL_Machines_having_buttons_from_a_Machintype_price_greater9700> 

XSL:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/> 

<xsl:template match="/ALL_Machines_having_buttons_from_a_Machintype_price_greater9700"> 
<humans> 
<xsl:for-each select="GreaterTypes"> 
<human> 
    <firstName><xsl:value-of select="typename"/></firstName> 
    <livingyears><xsl:value-of select="amount"/></livingyears> 
    <alifesince><xsl:value-of select="date"/></alifesince> 
</human> 

</xsl:for-each> 

</humans> 
</xsl:template> 

</xsl:stylesheet> 

私は何を得る:

<humans> 
<human> 
    <firstName>Grant and Sons</firstName> 
    <livingyears/> 
    <alifesince/> 
</human> 
</humans> 
+0

あなたのXSLTコードが動作していない、このXSLTを試してみてください。最初にを削除する必要があります。その後、期待どおりに動作します。 – Gerriet

+0

あなたは正しいですか?私は問題を見ました...これは私の問題を実証するための例です...何とか私の元のファイルではうまくいきません:(なぜか分かりません) –

+1

これまでの例を単純化すると良いです可能ですが、それはもちろんあなたが興味を持っている問題を再現していることを意味しています。今は単純化して問題を再現するまで元の部分に追加することができます。 – Gerriet

答えて

1

dateamountは、子孫ではなく子孫がより深いので、完全な相対パスを指定する必要があるという問題があります。

例えば、dateのためには、これを次のようになります。

<xsl:value-of select="purchasebillxml/purchasebill/date"/> 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/ALL_Machines_having_buttons_from_a_Machintype_price_greater9700"> 
<humans> 
<xsl:for-each select="GreaterTypes"> 
<human> 
    <firstName><xsl:value-of select="typename"/></firstName> 
    <livingyears><xsl:value-of select="purchasebillxml/purchasebill/product/amount"/></livingyears> 
    <alifesince><xsl:value-of select="purchasebillxml/purchasebill/date"/></alifesince> 
</human> 
</xsl:for-each> 
</humans> 
</xsl:template> 

</xsl:stylesheet> 
+0

非常にトリックをしてくれてありがとう! :) –

0

追加削除に追加の人間タグを使用する場合、for-each-loopをテンプレートマッチで置き換えます。このように:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/> 

<xsl:template match="/persons"> 
<humans> 
<xsl:apply-templates/> 
</humans> 
</xsl:template> 

<xsl:template match="person"> 
<human> 
    <firstName><xsl:value-of select="name"/></firstName> 
    <livingyears><xsl:value-of select="age"/></livingyears> 
    <alifesince><xsl:value-of select="birthday"/></alifesince> 
</human> 
</xsl:template> 

</xsl:stylesheet> 
0

あなたのXSLTは概ねOKです。

最初の<humans>を削除します。テンプレート の外にあり、一致する終了タグはありません。

コードをテストする目的で、私も削除しました。 xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl" (不要)。

私はあなたのコードを上記の修正でテストしました。結果はOKです。 チェック時http://xsltransform.net/a9Giww

実際の問題は、投稿に含まれているコードの外に隠れている可能性があります。 完全にあなたのコードを見てください。

関連する問題