我的XML是 -
<doc>
<blk_customer_Details>
<custno>1010101</custno>
</blk_customer_Details>
<blk_customer_Details>
<custno>2020202</custno>
</blk_customer_Details>
<blk_customer_Details>
<custno>3030303</custno>
</blk_customer_Details>
</doc>
我的XSLT是 -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<OPSC_IF_APPLICANT>
<xsl:for-each select="blk_customer_Details">
<xsl:variable name="counter" select="position()" />
<xsl:copy>
<xsl:choose>
<xsl:when test="$counter = 1">
<applicant_id><xsl:value-of select="custno"/></applicant_id>
</xsl:when>
<xsl:when test="$counter = 2">
<applicant_id1><xsl:value-of select="custno"/></applicant_id1>
</xsl:when>
<xsl:when test="$counter = 3">
<applicant_id2><xsl:value-of select="custno"/></applicant_id2>
</xsl:when>
</xsl:choose>
</xsl:copy>
</xsl:for-each>
</OPSC_IF_APPLICANT>
</xsl:template>
</xsl:stylesheet>
我希望在应用XSLT后获得以下XML -
<OPSC_IF_APPLICANT>
<applicant_id>1010101</applicant_id>
<applicant_id1>2020202</applicant_id1>
<applicant_id2>3030303</applicant_id2>
</OPSC_IF_APPLICANT>
我是XSLT的新手。我已经看到了一些关于使用position()函数的例子,我上面的XSLT应该可行。请让我知道我做错了什么。