العمل مع الصفات عقدة XML في XSLT
إذا كنت تستخدم XML و XSL، ثم قد جئت عبر وقت واحد، عندما يكون لديك للعب مع حولها سمات وقيم العقد XML في كنت XSL. هم الكثير من المواقع التي تحتوي على معلومات ينضب طويل حول هذا الموضوع، ولكن لا شيء وجدت كانت مختصرة ودقيقة ... وليس هذا البرنامج التعليمي 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
تحميل جميع الملفات المذكورة أعلاه هنا (245 تحميل)
مشاهدة هذا الفضاء، وسوف أظل تحديث هذه مع النتائج الجديدة ...










































