2008 2008年 4 4日

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

所以讓我們開始改變我們的上面的XML使用XSL

例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


下載上述所有文件(251下載)



觀看這個空間,我會不斷更新這一新的發現......


NDK的家 | 表達它 表示唇齶裂 表示Penmenship 表示敬畏 表達自己