5 Mart 2009, PERÅžEMBE
XSLT: öznitelik değeri sırasında değiştirme <xsl:copy>?
Bir XML belgesi var ve öznitelikleri için değerleri değiştirmek istiyorum.
İlk çıkış için giriş gelen her şeyi kullanarak kopyaladım:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
Ve şimdi herhangi bir öğe "property" adlı özniteliği "type" değerini değiştirmek istiyorum.
CEVAP
6 Mart 2009, Cuma
Bu sorun klasik bir çözüm vardır:the identity template kullanarak bastırıyor en temel ve güçlü XSLT tasarım modellerinden biri:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pNewType" select="'myNewType'"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="property/@type">
<xsl:attribute name="type">
<xsl:value-of select="$pNewType"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Bu XML belgesi üzerinde uygulandığında:
<t>
<property>value1</property>
<property type="old">value2</property>
</t>
istediği sonucu üretilir:
<t>
<property>value1</property>
<property type="myNewType">value2</property>
</t>
Bunu PaylaÅŸ:

AppSettings öznitelik değeri değiştirm...
Nasıl değeri{kullanıcı} $Eclipse şablo...
C XmlNode öznitelik değeri nasıl okunu...
Profesyonel Ürün Öznitelik Değeri Elde...
Öznitelik değeri üzerinden XPath düğüm...