3

私はこのようなxmlを持っています:

<article>
   <title> Test title - <literal> Compulsory - </literal> <fn> ABC </fn> 
   <comments> a comment</comments>
   </title>
</article>

変数内のすべての子ノード + 自己テキストを取得したい

$full_title = "テストのタイトル - 必須 - ABC"

コメント ノード テキストを除く。

以下は、タイトルノードのテキストが見つからない失敗した試みです。

<xsl:template name="test">
    <xsl:variable name="full_title" select="article/title/*[not(self::comments)][1]" />
    <xsl:variable name="width" select="45" /> 
                <xsl:choose>
                    <xsl:when test="string-length($full_title) &gt;    $width">
                        <xsl:value-of select="concat(substring($full_title,1,$width),'..')"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$full_title"/>    
                    </xsl:otherwise>
            </xsl:choose>
</xsl:template>
4

2 に答える 2

1

これを試して:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="/">
        <xsl:variable name="full-text">
            <xsl:apply-templates select="//*[not(self::comments)]" 
               mode="no-comments"/> 
        </xsl:variable>
        <xsl:value-of select="$full-text"/><!-- just for debug-->
    </xsl:template >

    <xsl:template match="*" mode="no-comments">
        <xsl:value-of select="text()"/>
    </xsl:template>
</xsl:stylesheet>

mode明確にするためにのみ使用される属性

于 2013-08-01T14:05:27.317 に答える