0

カスタム関数と同様の方法で XSLT を拡張するカスタム タグを作成する方法はありますか?

すなわち(私のxsltファイルで):

<xsl:template match="/">
<div>
  <my:customTag items="3" classname="foo"/>
</div>
</xsl:template>

期待される出力:

<div>
  <ul class="foo">
    <li>...</li>
    <li>...</li>
    <li>...</li>
  </ul>
<div>

現在、私はこれをやっています:

<xsl:template match="/">
<div>
  <xsl:copy-of select="my:customFunc(3,'foo')" />
</div>
</xsl:template>

私のcustomFuncはvbコードで次のようにします:

Public Function customFunc(ByVal n As Integer, ByVal classname as String) As System.Xml.XmlNode
            Dim newNode As System.Xml.XmlNode
            Dim doc As System.Xml.XmlDocument = New System.Xml.XmlDocument()
            Dim xmlContent As String = "<ul class=""" + classname + """>"

            For v As Integer = 0 To n
                xmlContent += "<li>" + someComplicatedCalc(n) + "</li>"
            Next
            xmlContent += "</ul>"


            doc.LoadXml(xmlContent)
            newNode = doc.DocumentElement

            Return newNode
        End Function

関数の代わりにタグを使いたい。

4

3 に答える 3

1

I am not aware of any support for this feature called custom extension elements with Microsoft's XslCompiledTransform and other processors, like XmlPrime or like Saxon (http://saxonica.com/html/documentation9.6/extensibility/instructions.html) don't seem to support it either with .NET.

于 2016-02-24T15:28:24.900 に答える
1

既存の VB.Net コードを使用したいが、ソース XML でより適切な構文を使用したい場合は、このテンプレートをスタイルシートに追加してみてください。

<xsl:template match="my:customTag">
  <xsl:copy-of select="my:customFunc(@items,@classname)" />
</xsl:template>

xpath セレクターは、<my:customTag items="3" classname="foo"/>

于 2016-02-24T16:02:45.347 に答える