Trabalhando com atributos nó XML XSLT
Se você usar XML e XSL, então você pode ter vindo através de um tempo, quando você tem que brincar com atributos e valores de nós XML em XSL você. Eles são um monte de sites com informação de fôlego longo sobre isso, mas nenhum que eu encontrei foram breve e preciso ... Esta é nenhum tutorial XML / XSL, mas a minha tentativa de colocar em conjunto uma espécie de fraude lista ...
A amostra XML que iremos trabalhar com esta aparência ...
<?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>
Então vamos começar a transformar o nosso XML acima usando XSL
Exemplo 1: Exibindo valor em um atributo escolhido
<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>
Resultado será parecido com HTML
Orange is the color and rich in vitamin C,
to get more information about <a href="http://www.orange.com" target="new">
Exemplo 2: Percorrer e mostrar todos os nomes de atributo XML e seus valores
<xsl:for-each select="/food/fruits/item/@*">
attribute name : <xsl:value-of select="name()"/>,
attribute value : <xsl:value-of select="."/> <br />
</xsl:for-each>
Resultado será parecido com 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
Download de todos os arquivos acima aqui (244 downloads)
Assista a este espaço, eu vou continuar atualizando esta com novas descobertas ...










































