<a>
XML 1.0を使用して、各タグ内のコンテンツを説明ノード内の文字数制限20にトリミングする必要があります。これがXMLです
<description>
This is text <a href="http://stackoverflow.com/posts/14718323/edit">http://stackoverflow.com/posts/14718323/edit</a>.
Also here is more text than we have another
<a href="http://stackoverflow.com/posts/14718323/edit">http://stackoverflow.com/posts/14718323/edit</a>.
</description>
私がそれを変えるために必要なのはこれです:
<description>
This is text <a href="http://stackoverflow.com/posts/14718323/edit">http://stacko</a>.
Also here is more text than we have another
<a href="http://stackoverflow.com/posts/14718323/edit">http://stacko</a>.
</description>
ほとんどのロジックを実行できますが、説明ノードを検索して「each」<a>を変換する「for-each」を実行するのに問題があります。
これは意味がありますか?助けていただければ幸いです。
**編集2/7/13 *
ここで提供された回答に基づいて、私は今ここにいます。
<xsl:template match="/">
<xsl:apply-templates select="//description"/>
</xsl:template>
<xsl:template match="a">
<a href="{@href}">
<xsl:value-of select="substring(normalize-space(),1,20)"/>
</a>
</xsl:template>
問題は、XSLに複数のテンプレートがあるため、「apply-templates」が機能しないことです。テンプレートを具体的に呼び出す必要があるので、「call-template」がルートになると思いました。「call-template」の唯一の問題は、参照する特定のXMLノードを指定する方法がわからないことです。これが私がこれまでにそれをハックした方法です(動作しません):
<xsl:template match="/">
<xsl:call-template name="trim_text"/>
</xsl:template>
<xsl:template name="trim_text" match="//description">
<a href="{@href}">
<xsl:value-of select="substring(normalize-space(),1,20)"/>
</a>
</xsl:template>
<xsl:template match="/">
これははるかに大きな関数で行われるため、最初の「call-template」はにある必要があります。だから私は3つのものが必要です:
1)XMLの内容との一貫性を保つためのHREF
<a>
2) 20pxにトリミングされるタグ間のテキスト
3)XMLで多くの変換を行うはるかに大きなxslテンプレート内からこのテンプレートを呼び出す必要があります。これは約7回のテンプレート呼び出しになります。