下面是我的输入请求。由于我的输入和XSLT都很长,所以我在这里缩短了它们。我将获得近10个ProductID的产品,我必须在不使用xsl:template match的情况下获取所有产品,因为我不能在XSLT中使用模板作为子元素。我应该如何用XSLT编写它以获得想要的输出?
输入:
<ChannelPartnerMembershipProfile>
<Dimension actionCode="4 ">
<ProductID>10000091</ProductID>
<ReceiverProductID>800GB</ReceiverProductID>
<DimensionStatusCode>02</DimensionStatusCode>
<StartDate>2020-12-07</StartDate>
<EndDate>2023-12-19</EndDate>
</Dimension>
<Dimension actionCode="4 ">
<ProductID>10000085</ProductID>
<ReceiverProductID>50GB</ReceiverProductID>
<DimensionStatusCode>02</DimensionStatusCode>
<StartDate>2020-12-06</StartDate>
<EndDate>2023-12-25</EndDate>
</Dimension>
</ChannelPartnerMembershipProfile>XSLT:
<xsl:for-each select="//Dimension">
<eep:EemblInternalProduct>
<xsl:value-of select="following-sibling::EndDate[1]"/>
<eep:EndDate>
<xsl:value-of select="$EndDate"/>
</eep:EndDate>
<eep:Name>
<xsl:value-of select="$ReceiverProductID"/>
</eep:Name>
<eep:Part>
<xsl:value-of select="ProductID"/>
</eep:Part>
<eep:StartDate>
<xsl:value-of select="$StartDate"/>
</eep:StartDate>
</eep:EemblInternalProduct>
</xsl:for-each>我的预期产出:
<eep:EemblInternalProduct>
<eep:EndDate>2023-12-19</eep:EndDate>
<eep:Name>800GB</eep:Name>
<eep:Part>10000091</eep:Part>
<eep:StartDate>2020-12-07</eep:StartDate>
</eep:EemblInternalProduct>
<eep:EemblInternalProduct>
<eep:EndDate>2023-12-25</eep:EndDate>
<eep:Name>50GB</eep:Name>
<eep:Part>10000085</eep:Part>
<eep:StartDate>2020-12-06</eep:StartDate>
</eep:EemblInternalProduct> 发布于 2020-12-29 08:18:29
我想在不使用“模板匹配”的情况下编写它,因为我不能在xslt中使用模板作为子元素。
没问题。您根本不需要嵌套<xsl:template>。这就是<xsl:apply-templates>的作用。
<xsl:template match="/">
<list>
<xsl:apply-templates select="//Dimension" />
</list>
</xsl:template>
<xsl:template match="Dimension">
<eep:EemblInternalProduct>
<eep:EndDate>
<xsl:value-of select="EndDate" />
</eep:EndDate>
<eep:Name>
<xsl:value-of select="ReceiverProductID" />
</eep:Name>
<eep:Part>
<xsl:value-of select="ProductID" />
</eep:Part>
<eep:StartDate>
<xsl:value-of select="StartDate" />
</eep:StartDate>
</eep:EemblInternalProduct>
</xsl:template>结果:
<list xmlns:eep="...">
<eep:EemblInternalProduct>
<eep:EndDate>2023-12-19</eep:EndDate>
<eep:Name>800GB</eep:Name>
<eep:Part>10000091</eep:Part>
<eep:StartDate>2020-12-07</eep:StartDate>
</eep:EemblInternalProduct>
<eep:EemblInternalProduct>
<eep:EndDate>2023-12-25</eep:EndDate>
<eep:Name>50GB</eep:Name>
<eep:Part>10000085</eep:Part>
<eep:StartDate>2020-12-06</eep:StartDate>
</eep:EemblInternalProduct>
</list>请注意,
<xsl:apply-templates>替换<xsl:for-each>.<xsl:value-of select="$EndDate" />,选择变量$EndDate的值。你没有这样的变数。您希望选择元素<EndDate>的值。一个用<xsl:value-of select="EndDate" />.完成的
https://stackoverflow.com/questions/65489023
复制相似问题