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 表示敬畏 表达自己