5

xsl:function を使用してカスタム文字列操作を追加する必要がある XSL スタイル シートがあります。しかし、関数をドキュメントのどこに配置するかを考え出すのに苦労しています。

私の XSL 簡略化は次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:my="myFunctions" xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:import href="Master.xslt"/>
  <xsl:template match="/">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <!-- starts actual layout -->
      <fo:page-sequence master-reference="first">
        <fo:flow flow-name="xsl-region-body">
          <!-- this defines a title level 1-->
          <fo:block xsl:use-attribute-sets="heading">
            HelloWorld
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
</xsl:stylesheet>

そして、単純な関数を入れたいのですが、たとえば、

  <xsl:function name="my:helloWorld">
    <xsl:text>Hello World!</xsl:text>
  </xsl:function>

しかし、関数を配置する場所がわかりません。ノードの下に配置すると、「xsl:function」は「xsl:stylesheet」要素の子にできないというエラーが表示されます。、ノードの下に置くと、同様のエラーが発生します。

関数はどこに配置すればよいですか?理想的には、関数を外部ファイルに入れて xsl ファイルにインポートしたいと考えています。

4

2 に答える 2

18

XSL バージョン 1.0 には xsl:function はありません。名前付きテンプレートを作成する必要があります

<xsl:template name="helloWorld">
  <xsl:text>Hello World!</xsl:text>
</xsl:template>

(...)

<xsl:template match="something">
  <xsl:call-template name="helloWorld"/>
</xsl:template>
于 2009-09-03T06:23:59.567 に答える
7

スタイルシートのバージョンを 2.0 にアップグレードすると、スタイルシート宣言で次のように指定できます。

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://www.**.com"> 

**あなたの選択は、あなたの希望に応じて何でも指定できます。次に、この下に機能を指定してください

<xsl:function name="func:helloWorld">
  <xsl:text>Hello World!</xsl:text>
</xsl:function>

次に、テンプレートで次のように使用できます

<xsl:template match="/">
<xsl:value-of select="func:helloWorld"/>
</xsl:template>
于 2011-12-08T08:34:01.873 に答える