XSLT 1.0:应用模板和模板模式

发布于 2024-12-01 07:22:12 字数 4681 浏览 0 评论 0原文

我有以下 XML:

<?xml version="1.0" encoding="UTF-8"?>
<Order>
<Item>
    <RECORD_ID>RECORD_ID</RECORD_ID>
    <ENTITY_CODE>ENTITY_CODE</ENTITY_CODE>
    <USER_CODE>USER_CODE</USER_CODE>
    <RECORD_DATE>RECORD_DATE</RECORD_DATE>
    <ITEM_CODE>ITEM_CODE</ITEM_CODE>
    <LINE_QUANTITY>LINE_QUANTITY</LINE_QUANTITY>
    <LINE_FREE_STOCK>LINE_FREE STOCK</LINE_FREE_STOCK>
    <LINE_PRICE>LINE_PRICE</LINE_PRICE>
    <LINE_DISCOUNT_PERCENT>LINE_DISCOUNT PERCENT</LINE_DISCOUNT_PERCENT>
</Item>
<Item>
    <RECORD_ID>9046</RECORD_ID>
    <ENTITY_CODE>12010601</ENTITY_CODE>
    <USER_CODE>122</USER_CODE>
    <RECORD_DATE>2011-08-24</RECORD_DATE>
    <ITEM_CODE>804-008165</ITEM_CODE>
    <LINE_QUANTITY>2</LINE_QUANTITY>
    <LINE_FREE_STOCK>1</LINE_FREE_STOCK>
</Item>
<Item>
    <RECORD_ID>9046</RECORD_ID>
    <ENTITY_CODE>12010601</ENTITY_CODE>
    <USER_CODE>122</USER_CODE>
    <RECORD_DATE>2011-08-24</RECORD_DATE>
    <ITEM_CODE>804-008161</ITEM_CODE>
    <LINE_QUANTITY>1</LINE_QUANTITY>
    <LINE_FREE_STOCK>1</LINE_FREE_STOCK>
</Item>
<Item>
    <RECORD_ID>9046</RECORD_ID>
    <ENTITY_CODE>12010601</ENTITY_CODE>
    <USER_CODE>122</USER_CODE>
    <RECORD_DATE>2011-08-24</RECORD_DATE>
    <ITEM_CODE>804-008225</ITEM_CODE>
    <LINE_QUANTITY>5</LINE_QUANTITY>
</Item>
</Order>

有时在 item 标记中我有元素 。如果发生这种情况,我必须在输出 XML 中创建一个附加位置。

现在我想出了这个样式表:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="UTF-8" method="xml" indent="yes"/>

<xsl:template match="/">
    <ORDERS05>
        <IDOC BEGIN="1">
            <xsl:apply-templates select="Order"/>
        </IDOC>
    </ORDERS05>
</xsl:template>

<xsl:template match="Order">
    <Header>
        <xsl:value-of select="'some header data'"/>
    </Header>
    <xsl:apply-templates select="Item[position() >1]"/>
    <xsl:apply-templates select="Item[position() >1 and child::LINE_FREE_STOCK]" mode="freestock"/>
</xsl:template>

<xsl:template match="Item">
        <position>
            <item>
                <number><xsl:value-of select="ITEM_CODE"/></number>
                <quantity><xsl:value-of select="LINE_QUANTITY"/></quantity>
            </item>
        </position>
</xsl:template>

<xsl:template match="Item[position() >1 and child::LINE_FREE_STOCK]" mode="freestock">
        <position>
            <item>
                <number><xsl:value-of select="ITEM_CODE"/></number>
                <freestock_quant><xsl:value-of select="LINE_FREE_STOCK"/></freestock_quant>
            </item>
        </position>
</xsl:template>

</xsl:stylesheet>

它创建了这个(简化的)所需输出:

<?xml version="1.0" encoding="UTF-8"?>
<ORDERS05>
<IDOC BEGIN="1">
    <Header>some header data</Header>
    <position>
        <item>
            <number>804-008165</number>
            <quantity>2</quantity>
        </item>
    </position>
    <position>
        <item>
            <number>804-008161</number>
            <quantity>1</quantity>
        </item>
    </position>
    <position>
        <item>
            <number>804-008225</number>
            <quantity>5</quantity>
        </item>
    </position>
    <position>
        <item>
            <number>804-008165</number>
            <freestock_quant>1</freestock_quant>
        </item>
    </position>
    <position>
        <item>
            <number>804-008161</number>
            <freestock_quant>1</freestock_quant>
        </item>
    </position>
</IDOC>
</ORDERS05>

804-008165 和 804-008161 显示两次 - 一次作为标准项目,一次作为具有各自数量的免费库存项目。

但我在这里忘记了什么吗?有什么我看不到的陷阱吗? 该 XSLT 足够强大吗?

I have the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<Order>
<Item>
    <RECORD_ID>RECORD_ID</RECORD_ID>
    <ENTITY_CODE>ENTITY_CODE</ENTITY_CODE>
    <USER_CODE>USER_CODE</USER_CODE>
    <RECORD_DATE>RECORD_DATE</RECORD_DATE>
    <ITEM_CODE>ITEM_CODE</ITEM_CODE>
    <LINE_QUANTITY>LINE_QUANTITY</LINE_QUANTITY>
    <LINE_FREE_STOCK>LINE_FREE STOCK</LINE_FREE_STOCK>
    <LINE_PRICE>LINE_PRICE</LINE_PRICE>
    <LINE_DISCOUNT_PERCENT>LINE_DISCOUNT PERCENT</LINE_DISCOUNT_PERCENT>
</Item>
<Item>
    <RECORD_ID>9046</RECORD_ID>
    <ENTITY_CODE>12010601</ENTITY_CODE>
    <USER_CODE>122</USER_CODE>
    <RECORD_DATE>2011-08-24</RECORD_DATE>
    <ITEM_CODE>804-008165</ITEM_CODE>
    <LINE_QUANTITY>2</LINE_QUANTITY>
    <LINE_FREE_STOCK>1</LINE_FREE_STOCK>
</Item>
<Item>
    <RECORD_ID>9046</RECORD_ID>
    <ENTITY_CODE>12010601</ENTITY_CODE>
    <USER_CODE>122</USER_CODE>
    <RECORD_DATE>2011-08-24</RECORD_DATE>
    <ITEM_CODE>804-008161</ITEM_CODE>
    <LINE_QUANTITY>1</LINE_QUANTITY>
    <LINE_FREE_STOCK>1</LINE_FREE_STOCK>
</Item>
<Item>
    <RECORD_ID>9046</RECORD_ID>
    <ENTITY_CODE>12010601</ENTITY_CODE>
    <USER_CODE>122</USER_CODE>
    <RECORD_DATE>2011-08-24</RECORD_DATE>
    <ITEM_CODE>804-008225</ITEM_CODE>
    <LINE_QUANTITY>5</LINE_QUANTITY>
</Item>
</Order>

Sometimes within the item tag I have the element <LINE_FREE_STOCK>. If that occurs I have to create an additional position in the output XML.

Now I came up with this style sheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="UTF-8" method="xml" indent="yes"/>

<xsl:template match="/">
    <ORDERS05>
        <IDOC BEGIN="1">
            <xsl:apply-templates select="Order"/>
        </IDOC>
    </ORDERS05>
</xsl:template>

<xsl:template match="Order">
    <Header>
        <xsl:value-of select="'some header data'"/>
    </Header>
    <xsl:apply-templates select="Item[position() >1]"/>
    <xsl:apply-templates select="Item[position() >1 and child::LINE_FREE_STOCK]" mode="freestock"/>
</xsl:template>

<xsl:template match="Item">
        <position>
            <item>
                <number><xsl:value-of select="ITEM_CODE"/></number>
                <quantity><xsl:value-of select="LINE_QUANTITY"/></quantity>
            </item>
        </position>
</xsl:template>

<xsl:template match="Item[position() >1 and child::LINE_FREE_STOCK]" mode="freestock">
        <position>
            <item>
                <number><xsl:value-of select="ITEM_CODE"/></number>
                <freestock_quant><xsl:value-of select="LINE_FREE_STOCK"/></freestock_quant>
            </item>
        </position>
</xsl:template>

</xsl:stylesheet>

It creates this (simplified) wanted output:

<?xml version="1.0" encoding="UTF-8"?>
<ORDERS05>
<IDOC BEGIN="1">
    <Header>some header data</Header>
    <position>
        <item>
            <number>804-008165</number>
            <quantity>2</quantity>
        </item>
    </position>
    <position>
        <item>
            <number>804-008161</number>
            <quantity>1</quantity>
        </item>
    </position>
    <position>
        <item>
            <number>804-008225</number>
            <quantity>5</quantity>
        </item>
    </position>
    <position>
        <item>
            <number>804-008165</number>
            <freestock_quant>1</freestock_quant>
        </item>
    </position>
    <position>
        <item>
            <number>804-008161</number>
            <freestock_quant>1</freestock_quant>
        </item>
    </position>
</IDOC>
</ORDERS05>

804-008165 and 804-008161 show up twice - once as a standard item and once as the free stock item with the respective quantities.

But did I forget anything here? Is there some sort of pitfall I don't see?
Is that XSLT robust enough?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

2024-12-08 07:22:12

正如其他人所指出的,问题出在这段代码中

<xsl:apply-templates select="Item"/> 
<xsl:apply-templates select="Item[child::LINE_FREE_STOCK]" mode="freestock"/> 

如果有一个子Item,它有一个子LINE_FREE_STOCK,则模板将应用于这个 Item 元素两次 - 这是在输出中获取重复项的方法。

转换可以显着缩短,并且根本不需要模式或显式条件指令

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output encoding="UTF-8" indent="yes"/>

 <xsl:template match="/">
    <ORDERS05>
        <IDOC BEGIN="1">
            <xsl:apply-templates select="Order"/>
        </IDOC>
    </ORDERS05>
 </xsl:template>

 <xsl:template match="Order">
    <Header>
        <xsl:value-of select="'some header data'"/>
    </Header>
        <xsl:apply-templates select="Item[position() >1]"/>
 </xsl:template>

 <xsl:template match="Item">
  <position>
    <item>
      <number>
        <xsl:value-of select="ITEM_CODE"/>
      </number>

      <xsl:apply-templates select=
        "self::node()[not(LINE_FREE_STOCK)]/LINE_QUANTITY
       |
         LINE_FREE_STOCK"/>
     </item>
  </position>
 </xsl:template>

 <xsl:template match="LINE_QUANTITY">
   <quantity>
     <xsl:value-of select="."/>
   </quantity>
 </xsl:template>

 <xsl:template match="LINE_FREE_STOCK">
   <freestock_quant>
     <xsl:value-of select="."/>
   </freestock_quant>
 </xsl:template>
</xsl:stylesheet>

当此转换应用于提供的 XML 文档时

<Order>
    <Item>
        <RECORD_ID>RECORD_ID</RECORD_ID>
        <ENTITY_CODE>ENTITY_CODE</ENTITY_CODE>
        <USER_CODE>USER_CODE</USER_CODE>
        <RECORD_DATE>RECORD_DATE</RECORD_DATE>
        <ITEM_CODE>ITEM_CODE</ITEM_CODE>
        <LINE_QUANTITY>LINE_QUANTITY</LINE_QUANTITY>
        <LINE_FREE_STOCK>LINE_FREE STOCK</LINE_FREE_STOCK>
        <LINE_PRICE>LINE_PRICE</LINE_PRICE>
        <LINE_DISCOUNT_PERCENT>LINE_DISCOUNT PERCENT</LINE_DISCOUNT_PERCENT>
    </Item>
    <Item>
        <RECORD_ID>9046</RECORD_ID>
        <ENTITY_CODE>12010601</ENTITY_CODE>
        <USER_CODE>122</USER_CODE>
        <RECORD_DATE>2011-08-24</RECORD_DATE>
        <ITEM_CODE>804-008165</ITEM_CODE>
        <LINE_QUANTITY>2</LINE_QUANTITY>
        <LINE_FREE_STOCK>1</LINE_FREE_STOCK>
    </Item>
    <Item>
        <RECORD_ID>9046</RECORD_ID>
        <ENTITY_CODE>12010601</ENTITY_CODE>
        <USER_CODE>122</USER_CODE>
        <RECORD_DATE>2011-08-24</RECORD_DATE>
        <ITEM_CODE>804-008161</ITEM_CODE>
        <LINE_QUANTITY>1</LINE_QUANTITY>
        <LINE_FREE_STOCK>1</LINE_FREE_STOCK>
    </Item>
    <Item>
        <RECORD_ID>9046</RECORD_ID>
        <ENTITY_CODE>12010601</ENTITY_CODE>
        <USER_CODE>122</USER_CODE>
        <RECORD_DATE>2011-08-24</RECORD_DATE>
        <ITEM_CODE>804-008225</ITEM_CODE>
        <LINE_QUANTITY>5</LINE_QUANTITY>
    </Item>
</Order>

想要的,产生正确的结果

<ORDERS05>
   <IDOC BEGIN="1">
      <Header>some header data</Header>
      <position>
         <item>
            <number>804-008165</number>
            <freestock_quant>1</freestock_quant>
         </item>
      </position>
      <position>
         <item>
            <number>804-008161</number>
            <freestock_quant>1</freestock_quant>
         </item>
      </position>
      <position>
         <item>
            <number>804-008225</number>
            <quantity>5</quantity>
         </item>
      </position>
   </IDOC>
</ORDERS05>

As others have noted, the problem is in this code:

<xsl:apply-templates select="Item"/> 
<xsl:apply-templates select="Item[child::LINE_FREE_STOCK]" mode="freestock"/> 

If there is a child Item that has a child LINE_FREE_STOCK, templates would be applied on this Item element twice -- here is how you get the repetitions in the output.

The transformation can be significantly shortened and it doesn't need modes or explicit conditional instructions at all:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output encoding="UTF-8" indent="yes"/>

 <xsl:template match="/">
    <ORDERS05>
        <IDOC BEGIN="1">
            <xsl:apply-templates select="Order"/>
        </IDOC>
    </ORDERS05>
 </xsl:template>

 <xsl:template match="Order">
    <Header>
        <xsl:value-of select="'some header data'"/>
    </Header>
        <xsl:apply-templates select="Item[position() >1]"/>
 </xsl:template>

 <xsl:template match="Item">
  <position>
    <item>
      <number>
        <xsl:value-of select="ITEM_CODE"/>
      </number>

      <xsl:apply-templates select=
        "self::node()[not(LINE_FREE_STOCK)]/LINE_QUANTITY
       |
         LINE_FREE_STOCK"/>
     </item>
  </position>
 </xsl:template>

 <xsl:template match="LINE_QUANTITY">
   <quantity>
     <xsl:value-of select="."/>
   </quantity>
 </xsl:template>

 <xsl:template match="LINE_FREE_STOCK">
   <freestock_quant>
     <xsl:value-of select="."/>
   </freestock_quant>
 </xsl:template>
</xsl:stylesheet>

When this transformation is applied on the provided XML document:

<Order>
    <Item>
        <RECORD_ID>RECORD_ID</RECORD_ID>
        <ENTITY_CODE>ENTITY_CODE</ENTITY_CODE>
        <USER_CODE>USER_CODE</USER_CODE>
        <RECORD_DATE>RECORD_DATE</RECORD_DATE>
        <ITEM_CODE>ITEM_CODE</ITEM_CODE>
        <LINE_QUANTITY>LINE_QUANTITY</LINE_QUANTITY>
        <LINE_FREE_STOCK>LINE_FREE STOCK</LINE_FREE_STOCK>
        <LINE_PRICE>LINE_PRICE</LINE_PRICE>
        <LINE_DISCOUNT_PERCENT>LINE_DISCOUNT PERCENT</LINE_DISCOUNT_PERCENT>
    </Item>
    <Item>
        <RECORD_ID>9046</RECORD_ID>
        <ENTITY_CODE>12010601</ENTITY_CODE>
        <USER_CODE>122</USER_CODE>
        <RECORD_DATE>2011-08-24</RECORD_DATE>
        <ITEM_CODE>804-008165</ITEM_CODE>
        <LINE_QUANTITY>2</LINE_QUANTITY>
        <LINE_FREE_STOCK>1</LINE_FREE_STOCK>
    </Item>
    <Item>
        <RECORD_ID>9046</RECORD_ID>
        <ENTITY_CODE>12010601</ENTITY_CODE>
        <USER_CODE>122</USER_CODE>
        <RECORD_DATE>2011-08-24</RECORD_DATE>
        <ITEM_CODE>804-008161</ITEM_CODE>
        <LINE_QUANTITY>1</LINE_QUANTITY>
        <LINE_FREE_STOCK>1</LINE_FREE_STOCK>
    </Item>
    <Item>
        <RECORD_ID>9046</RECORD_ID>
        <ENTITY_CODE>12010601</ENTITY_CODE>
        <USER_CODE>122</USER_CODE>
        <RECORD_DATE>2011-08-24</RECORD_DATE>
        <ITEM_CODE>804-008225</ITEM_CODE>
        <LINE_QUANTITY>5</LINE_QUANTITY>
    </Item>
</Order>

the wanted, correct result is produced:

<ORDERS05>
   <IDOC BEGIN="1">
      <Header>some header data</Header>
      <position>
         <item>
            <number>804-008165</number>
            <freestock_quant>1</freestock_quant>
         </item>
      </position>
      <position>
         <item>
            <number>804-008161</number>
            <freestock_quant>1</freestock_quant>
         </item>
      </position>
      <position>
         <item>
            <number>804-008225</number>
            <quantity>5</quantity>
         </item>
      </position>
   </IDOC>
</ORDERS05>

这是因为您有两个项目匹配模板:

<xsl:template match="Item">
  <xsl:if test="position() > 1">
    <position>
      <item>
        <number><xsl:value-of select="ITEM_CODE"/></number>
        <quantity><xsl:value-of select="LINE_QUANTITY"/></quantity>
      </item>
    </position>
  </xsl:if>
</xsl:template>

<xsl:template match="Item[child::LINE_FREE_STOCK]" mode="freestock">
  <xsl:if test="position() > 1">            
    <position>
      <item>
        <number><xsl:value-of select="ITEM_CODE"/></number>
        <freestock_quant><xsl:value-of select="LINE_FREE_STOCK"/></freestock_quant>
      </item>
    </position>
  </xsl:if>
</xsl:template>

首先匹配默认项目模板,然后具有 LINE_FREE_STOCK 的项目也与具有子 LINE_FREE_STOCK 模板的项目匹配,因此具有 LINE_FREE_STOCK 的项目重复。

相反,为什么不只使用一个模板,如下所示:

<xsl:template match="Item">
  <xsl:if test="position() > 1">
    <position>
      <item>
        <number><xsl:value-of select="ITEM_CODE"/></number>
        <xsl:choose>
          <xsl:when test="child::LINE_FREE_STOCK">
            <freestock_quant><xsl:value-of select="LINE_FREE_STOCK"/></freestock_quant>
          </xsl:when>
          <xsl:otherwise>
            <quantity><xsl:value-of select="LINE_QUANTITY"/></quantity>
          </xsl:otherwise>
        </xsl:choose>
      </item>
    </position>
  </xsl:if>
</xsl:template>

使用单个模板,您的订单模板也得到简化:

<xsl:template match="Order">
  <Header>
    <xsl:value-of select="'some header data'"/>
  </Header>
  <xsl:apply-templates select="Item"/>
</xsl:template>

这样您也不需要使用模式。

This is because you have two match templates for Item:

<xsl:template match="Item">
  <xsl:if test="position() > 1">
    <position>
      <item>
        <number><xsl:value-of select="ITEM_CODE"/></number>
        <quantity><xsl:value-of select="LINE_QUANTITY"/></quantity>
      </item>
    </position>
  </xsl:if>
</xsl:template>

<xsl:template match="Item[child::LINE_FREE_STOCK]" mode="freestock">
  <xsl:if test="position() > 1">            
    <position>
      <item>
        <number><xsl:value-of select="ITEM_CODE"/></number>
        <freestock_quant><xsl:value-of select="LINE_FREE_STOCK"/></freestock_quant>
      </item>
    </position>
  </xsl:if>
</xsl:template>

First the default Item template matches and then the Item's with LINE_FREE_STOCK also matches the Item with child LINE_FREE_STOCK template, hence the duplicate for Item's with LINE_FREE_STOCK.

Instead why not just use one template, like this:

<xsl:template match="Item">
  <xsl:if test="position() > 1">
    <position>
      <item>
        <number><xsl:value-of select="ITEM_CODE"/></number>
        <xsl:choose>
          <xsl:when test="child::LINE_FREE_STOCK">
            <freestock_quant><xsl:value-of select="LINE_FREE_STOCK"/></freestock_quant>
          </xsl:when>
          <xsl:otherwise>
            <quantity><xsl:value-of select="LINE_QUANTITY"/></quantity>
          </xsl:otherwise>
        </xsl:choose>
      </item>
    </position>
  </xsl:if>
</xsl:template>

Using the single template your Order template is also simplified:

<xsl:template match="Order">
  <Header>
    <xsl:value-of select="'some header data'"/>
  </Header>
  <xsl:apply-templates select="Item"/>
</xsl:template>

This way you do not need to use Modes either.

暮光沉寂 2024-12-08 07:22:12

目前尚不清楚想要的输出是什么。也许您想要:

<xsl:apply-templates select="Item[not(LINE_FREE_STOCK)"/>
<xsl:apply-templates select="Item[LINE_FREE_STOCK]" mode="freestock"/>

代替您的

  <xsl:apply-templates select="Item"/>
  <xsl:apply-templates select="Item[child::LINE_FREE_STOCK]" mode="freestock"/>

It's not clear what is the wanted output. Perhaps you want:

<xsl:apply-templates select="Item[not(LINE_FREE_STOCK)"/>
<xsl:apply-templates select="Item[LINE_FREE_STOCK]" mode="freestock"/>

in place of your

  <xsl:apply-templates select="Item"/>
  <xsl:apply-templates select="Item[child::LINE_FREE_STOCK]" mode="freestock"/>
九局 2024-12-08 07:22:12

您需要额外的过滤

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="UTF-8" method="xml" indent="yes"/>

<xsl:template match="/">
    <ORDERS05>
        <IDOC BEGIN="1">
            <xsl:apply-templates select="Order"/>
        </IDOC>
    </ORDERS05>
</xsl:template>

<xsl:template match="Order">
    <Header>
        <xsl:value-of select="'some header data'"/>
    </Header>
    <xsl:apply-templates select="Item[not(child::LINE_FREE_STOCK)]"/>
    <xsl:apply-templates select="Item[child::LINE_FREE_STOCK]" mode="freestock"/>
</xsl:template>

<xsl:template match="Item">
    <xsl:if test="position() > 1">
        <position>
            <item>
                <number><xsl:value-of select="ITEM_CODE"/></number>
                <quantity><xsl:value-of select="LINE_QUANTITY"/></quantity>
            </item>
        </position>
    </xsl:if>
</xsl:template>

<xsl:template match="Item[child::LINE_FREE_STOCK]" mode="freestock">
    <xsl:if test="position() > 1">            
        <position>
            <item>
                <number><xsl:value-of select="ITEM_CODE"/></number>
                <freestock_quant><xsl:value-of select="LINE_FREE_STOCK"/></freestock_quant>
            </item>
        </position>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>

You would need an addition filtering

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="UTF-8" method="xml" indent="yes"/>

<xsl:template match="/">
    <ORDERS05>
        <IDOC BEGIN="1">
            <xsl:apply-templates select="Order"/>
        </IDOC>
    </ORDERS05>
</xsl:template>

<xsl:template match="Order">
    <Header>
        <xsl:value-of select="'some header data'"/>
    </Header>
    <xsl:apply-templates select="Item[not(child::LINE_FREE_STOCK)]"/>
    <xsl:apply-templates select="Item[child::LINE_FREE_STOCK]" mode="freestock"/>
</xsl:template>

<xsl:template match="Item">
    <xsl:if test="position() > 1">
        <position>
            <item>
                <number><xsl:value-of select="ITEM_CODE"/></number>
                <quantity><xsl:value-of select="LINE_QUANTITY"/></quantity>
            </item>
        </position>
    </xsl:if>
</xsl:template>

<xsl:template match="Item[child::LINE_FREE_STOCK]" mode="freestock">
    <xsl:if test="position() > 1">            
        <position>
            <item>
                <number><xsl:value-of select="ITEM_CODE"/></number>
                <freestock_quant><xsl:value-of select="LINE_FREE_STOCK"/></freestock_quant>
            </item>
        </position>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文