XSLTでXMLノードの属性の操作
XMLとXSLを使用する場合は、属性とXSLでXMLノードの値で遊んでする必要がある場合、あなたは、時間に出くわすかもしれません。 彼らはこのことについて長いったらしい情報を持つサイトの負荷ですが、私が見つけたどれも簡単かつ正確ませんでした...これは、XML / XSLチュートリアルではありませんが、私の試みは、チートリストのいくつかの並べ替えをまとめるために...
私たちが仕事するサンプルXMLは次のようになります。...
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="food.xsl"?>
<food>
<fruits type="tropical">
<item name="mango" moreinfo="http://www.mango.com">Mango is the king of fruits</item>
<item name="banana" moreinfo="http://www.banana.com">Banana once a day , keeps the doctor away</item>
<item name="orange" moreinfo="http://www.orange.com">Orange is the color and rich in vitamin C</item>
<item name="Papaya" moreinfo="http://www.papaya.com">Papaya - Hot when raw, cold when ripe</item>
</fruits>
</food>
したがって、XSLを使用して、私たちの上記のXMLを変換を開始できます
例1:選択した属性に値を表示する
<xsl:value-of select="/food/fruits/item[@name='orange']" /><br />
to get more information about <a href="{/food/fruits/item[@name='orange']/@moreinfo}" target="new" ><xsl:value-of select="/food/fruits/item[@name='orange']/@name" /> </a>
HTMLの出力結果は次のようになります
Orange is the color and rich in vitamin C,
to get more information about <a href="http://www.orange.com" target="new">
例2:ループして、すべてのXML属性名とその値を表示する
<xsl:for-each select="/food/fruits/item/@*">
attribute name : <xsl:value-of select="name()"/>,
attribute value : <xsl:value-of select="."/> <br />
</xsl:for-each>
HTMLの出力結果は次のようになります
attribute name : name, attribute value : mango
attribute name : moreinfo, attribute value : http://www.mango.com
attribute name : name, attribute value : banana
attribute name : moreinfo, attribute value : http://www.banana.com
attribute name : name, attribute value : orange
attribute name : moreinfo, attribute value : http://www.orange.com
attribute name : name, attribute value : Papaya
attribute name : moreinfo, attribute value : http://www.papaya.com
(245ダウンロード)ここで、上記のすべてのファイルをダウンロード
このスペースを見て、私は新しい知見でこれを更新しておこう...










































