2

私はこのようなxmlファイルを持っています:receipt.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xml" href="receipt.xslt"?>
    <printedslip>
      <pos>
        <posno>11546546</posno>
      </pos>
      <store>
        <storeno>1</storeno>
        <storename>Store 01</storename>
        <orgno>001</orgno>
        <postalcode>550</postalcode>
      </store>
      <cashier>
        <userno>1</userno>
        <name>Sara</name>
      </cashier>
      <headertext>Receipt Profile Header</headertext>
    </printedslip>

およびxsltファイル:recipient.xslt

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:include href="params.xslt"/>
  <xsl:include href="store.xslt"/>
  <xsl:include href="headergroup.xslt"/>

  <xsl:output method="text" />
  <xsl:strip-space elements="*"/>

  <xsl:template match="store">
    <xsl:call-template name="store">
      <xsl:with-param name="value" select="store"/>
      <xsl:with-param name="store_no"  select="$store_no"/>    
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="headertext">
    <xsl:call-template name="receiptheader">
      <xsl:with-param name="value" select="headertext"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="cashier">
    <xsl:call-template name="cashier">
      <xsl:with-param name="value" select="cashier"/>
      <xsl:with-param name="cashier" select="$cashier"/>
    </xsl:call-template>
  </xsl:template>
</xsl:stylesheet>

テンプレートがXSLTファイルに追加された順序で形成された出力テキストを受け取ることを期待しています。代わりに、最初にストア情報、キャッシャー、ヘッダーテキストを、ノードがXMLファイルに表示される順序で受け取ります。XSLTファイルから注文したい:ストア、ヘッダーテキスト、キャッシャー。

これに対する解決策はありますか?

4

2 に答える 2

4

印刷された伝票に一致するテンプレートを追加すると、子要素を呼び出す順序を定義できます。

<xsl:template match="printedslip">
    <xsl:apply-templates select="store"/>
    <xsl:apply-templates select="headertext"/>
    <xsl:apply-templates select="cashier"/>
</xsl:template>

それ以外の場合、順序は入力XML(ストア、キャッシャー、ヘッダーテキスト)によって異なります。XSLT内のテンプレートの順序は、printedslipの要素の順序には影響しません。

一般に、XSLTプロセッサは、入力XMLのすべての要素を上から下に実行します。したがって、その順序が必要ない場合は、プロセッサに(xsltで)そのことを通知する必要があります。

于 2012-08-23T08:37:48.960 に答える
1

私はあなたと一緒xsl:apply-templateにあなたの目標を達成できると思います

于 2012-08-23T08:09:49.230 に答える