これらのデータ セットがあり、特定の値を削除したいと考えています。このメソッドは、必要なものを削除しましたが、それとともに他の値も削除しました。
<Address>
<Row>
<LD>Dwelling place</LD>
<LN>Dwelling (Part Of)</LN>
</Row>
<Row>
<LD>jarkatar</LD>
<LN>Edmund's Home</LN>
</Row>
</Address>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:Aa="Aa:Aa">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<Aa:LNDeletes>
<del>(Part Of)</del>
<Aa:LNDeletes>
<xsl:variable name="vLocNameDels" select="document('')/*/Aa:LNDeletes/*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="LN/text()">
<xsl:call-template name="makeDeletes">
<xsl:with-param name="pDeletes" select="$vLocNameDels"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="makeDeletes">
<xsl:param name="pText" select="."/>
<xsl:param name="pDeletes"/>
<xsl:variable name="vDelText" select="$pDeletes[contains($pText, .)][1]"/>
<xsl:if test="$vDelText">
<xsl:variable name="vRough">
<xsl:value-of select="substring-before($pText, $vDelText)"/>
<xsl:value-of select="substring-after($pText, $vDelText)"/>
</xsl:variable>
<xsl:value-of select="normalize-space($vRough)"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
上記のコードで私はこれを得ました
<Address>
<Row>
<LD>Dwelling place</LD>
<LN>Dwelling</LN>
</Row>
<Row>
<LD>jarkatar</LD>
<LN></LN>
</Row>
これの代わりに
<Address>
<Row>
<LD>Dwelling place</LD>
<LN>Dwelling</LN>
</Row>
<Row>
<LD>jarkatar </LD>
<LN>Edmund's Home</LN>
</Row>
削除されたコード
- (の一部) 私が欲しかったもの
- 削除するつもりのなかったエドマンドの家