2

XML のスーパー タグに特定の単語が含まれている場合にサブ タグが選択されないように、XSLT を変更しようとしています。

<para>この例では、スーパー タグ<formalpara>に「Galaxy」という単語が含まれている場合にサブ タグを表示したくありません。

前もって感謝します。

私のXML

<formalpara>
Galaxy
<para>
<bridgehead>Galaxy Zoo</bridgehead>
    <sliceXML>Galaxy</sliceXML>
    The human eye is far better at identifying characteristics of galaxies 
    than any computer. So Galaxy Zoo has called for everyday citizens to 
    help in a massive identification project. Well over a hundred thousand 
    people have helped identify newly discovered galaxies. Now you can, too.
</para>
</formalpara>

私の XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" version="1.0">

<xsl:template match="/">
    <xsl:call-template name="results"/>
    <xsl:message>FROM simpleHMHTransform XSLT8</xsl:message>
</xsl:template>

<xsl:template name="results">
    <xsl:for-each select="//formalpara">
        <xsl:call-template name="formalpara"/>
    </xsl:for-each>
    <xsl:for-each select="//para">
        <xsl:call-template name="para"/>
    </xsl:for-each>
</xsl:template>

<xsl:template name="formalpara">
<div id="formalpara">
    <xsl:copy-of select="text()"/>
</div>
</xsl:template>

<xsl:template name="para">
<div id="para">
    <xsl:copy-of select="text()"/>
</div>
</xsl:template>

私の現在の出力

<?xml version="1.0" encoding="UTF-8"?><div xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" id="formalpara">
Galaxy

</div><div xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" id="para">


    The human eye is far better at identifying characteristics of galaxies 
    than any computer. So Galaxy Zoo has called for everyday citizens to 
    help in a massive identification project. Well over a hundred thousand 
    people have helped identify newly discovered galaxies. Now you can, too.
</div>

私の望む出力

<?xml version="1.0" encoding="UTF-8"?><div xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" id="formalpara">
 Galaxy
</div>
4

1 に答える 1

2

xsl:apply-templates名前付きテンプレートを呼び出す代わりに、実際に行う必要があります。次に、このテンプレートを追加できます。

<xsl:template match="formalpara[contains(text(),'Galaxy')]/para"/>

後で完全な例を挙げることができます。


完全な例:

XML 入力

<formalpara>
    Galaxy
    <para>
        <bridgehead>Galaxy Zoo</bridgehead>
        <sliceXML>Galaxy</sliceXML>
        The human eye is far better at identifying characteristics of galaxies 
        than any computer. So Galaxy Zoo has called for everyday citizens to 
        help in a massive identification project. Well over a hundred thousand 
        people have helped identify newly discovered galaxies. Now you can, too.
    </para>
</formalpara>

XSLT1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:sparql-results="http://www.w3.org/2005/sparql-results#">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="formalpara">
        <div id="formalpara">
            <xsl:apply-templates/>
        </div>
    </xsl:template>

    <xsl:template match="formalpara[contains(text(),'Galaxy')]/para"/>

    <xsl:template match="para">
        <div id="para">
            <xsl:apply-templates/>
        </div>
    </xsl:template>

</xsl:stylesheet>

XML 出力

<div xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" id="formalpara">
    Galaxy
    </div>

注: また、 を に変更して、 の直接の子であるテキストのみを参照するようにしましcontains()た。contains(text(),'Galaxy')formalpara

于 2012-09-21T16:23:11.427 に答える