1

誰かが同じような問題を抱えていたのかもしれません。入力 XML ファイルを XSL を使用して変換する必要があります。

<decision>
    <akapit nr = 1>
           This is <b>important</b> decision for the query number <i>0123456</i>
    </akapit>
</decision>

<b></b>出力として、要素内のテキストを太字で、要素<i></i>をイタリック体で表示する html ドキュメントが必要です。<akapit>したがって、基本的には、サブ要素の名前に応じて名前が付けられた XML 要素から出力 HTML をフォーマットする必要があります。そのような場合に XSL テンプレートを使用する方法はありますか?

4

3 に答える 3

2

このような問題への基本的なアプローチは、

<xsl:template match="akapit">
  <div>
   <xsl:copy-of select="node()"/>
  </div>
</xsl:template>

XML 入力が、HTML が使用するものと同じ要素 (太字や斜体など) を使用している限り、これで十分です。

入力 XML に他の要素がある場合など

<decision>
    <akapit nr = 1>
           This is <bold>important</bold> decision for the query number <i>0123456</i>
    </akapit>
</decision>

次に、たとえばものを変換する必要があります

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

<xsl:template match="akapit//*">
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="akapit//bold">
  <b>
    <xsl:apply-templates/>
  </b>
</xsl:template>
于 2012-09-26T09:28:04.107 に答える
1

マークアップ要素の名前が、対応する Html 要素の名前と同じでない場合、たとえば次のようになります。

<decision>
    <akapit nr="1">
    This is 
        <bold>important</bold> decision for the query number
        <italic>0123456</italic>
    </akapit>
</decision>

次に、同一性ルールの非常に単純なアプリケーションは次のとおりです。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>

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

 <xsl:template match="bold"><b><xsl:apply-templates/></b></xsl:template>
 <xsl:template match="italic"><i><xsl:apply-templates/></i></xsl:template>

 <xsl:template match="/*"><xsl:apply-templates/></xsl:template>
</xsl:stylesheet>

この変換が上記の XML ドキュメントに適用されると、必要な正しい結果が生成されます。

<div>
    This is 
        <b>important</b> decision for the query number
        <i>0123456</i>
</div>

注意:後者は、選択したノードをさらに処理する柔軟性を持たないため、使用することをお勧めします。それらをコピーするだけですxsl:apply-templatesxsl:copy-of

于 2012-09-26T12:51:12.860 に答える
0

私があなたを正しく理解していれば、要素copy-ofの下のすべてを複製するために使用できますakapit

<xsl:template match="/decision/akapit[@nr='1']">
    <xsl:copy-of select="child::node()"/>
</xsl:template>
于 2012-09-26T09:33:44.277 に答える