[英]convert xslt2.0 to xslt1.0 syntax
I'm new to XSLT and i got to understand from my team that the current xml parser we have supports only version 1.0.我是 XSLT 的新手,我从我的团队那里了解到,我们目前拥有的 xml 解析器仅支持 1.0 版。 I would need help here to convert my current xslt 2.0 code to version 1.0我需要帮助将我当前的 xslt 2.0 代码转换为 1.0 版
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/Root">
<!-- header -->
<xsl:text>id|parent_id</xsl:text>
<xsl:value-of select="$newline"/>
<!-- data -->
<xsl:for-each select="Package">
<xsl:variable name="b-id" select="Business_ID" />
<!-- TPFC data -->
<xsl:for-each select="TPFC">
<xsl:variable name="total_level" select="count(.//.//Parent)+1"/>
<xsl:call-template name="prod-family">
<xsl:with-param name="total_level" select="$total_level"/>
<xsl:with-param name="b_id" select="$b-id"/>
</xsl:call-template>
<xsl:for-each select="//Parent">
<!-----Question 2------->
<xsl:call-template name="prod-family">
<xsl:with-param name="total_level" select="$total_level"/>
<xsl:with-param name="b_id" select="$b-id"/>
</xsl:call-template>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<!-----Question 1------->
<xsl:template name="prod-family">
<xsl:param name="total_level"/>
<xsl:param name="b_id"/>
<xsl:value-of select="reverse(.//Parent/Name), translate(Name,' ','')" separator="_" />
<xsl:value-of select="$separator"/>
<xsl:value-of select="reverse(.//Parent/Name)" separator="_" />
<xsl:value-of select="$separator"/>
<xsl:value-of select="$newline"/>
</xsl:template>
</xsl:stylesheet> </xsl:样式表>
XML For the above is XML 对于上面是
<?xml version="1.0" encoding="UTF-8"?>
<Root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Package ID="1122" BusinessID="001233" Version="19.0.2" xsi:type="Doms">
<Name>ABC</Name>
<Description> Desc sample</Description>
<Category>54</Category>
<Business_ID>001233</Business_ID>
<TPFC ID="76" xsi:type="TPFC" Pattern="Th_Branch">
<Name>AM</Name>
<Parent ID="11d" xsi:type="TPFC" Pattern="Th_Branch">
<Description>Mob1</Description>
<Name>Mob1</Name>
<Parent ID="12F" xsi:type="TPFC" Pattern="Th_Branch">
<Description>Mob2</Description>
<Name>Mob2</Name>
</Parent>
</Parent>
</TPFC>
</Package>
</Root>
This is the result这是结果
| id | parent_id |
| Mob2_Mob1_AM | Mob2_Mob1 |
| Mob2_Mob1 | Mob2 |
| Mob2 | |
In the above example, I have implemented the concatenation using XSLT 2.0 in two places (check template - prod-family ) where在上面的示例中,我在两个地方(检查模板 - prod-family )使用 XSLT 2.0 实现了连接,其中
id - Concatenation of all names from its root parent to current name in the below example it will be Mob2_Mob1_AM parent_id - Concatenation of all parent names from its root parent id - 在下面的示例中,从其根父级到当前名称的所有名称的连接将是 Mob2_Mob1_AM parent_id - 从其根父级的所有父级名称的连接
At a quick glance the only 2.0 constructs here are the call on reverse()
, and the use of xsl:value-of/@separator
.快速浏览一下,这里仅有的 2.0 构造是对reverse()
的调用,以及xsl:value-of/@separator
。 These are used together.这些是一起使用的。 You should be able to do something like:您应该能够执行以下操作:
<xsl:for-each select=".//Parent/Name | ./Name">
<xsl:sort select="-position()"/>
<xsl:value-of select="."/>
<xsl:if test="position() != last()">_</xsl:if>
</xsl:for-each>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.