how to control multiple tags not neccessary that to repeat again
here i m target a data with table of CTD_CTD_PKG_ID in my xslt but some tags were having data pretty same that type of tags we have to control not to repeat once more
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table>
<RECORD_TYPE_CODE>CTD</RECORD_TYPE_CODE>
<MSG_TYPE_CODE>O102</MSG_TYPE_CODE>
<CTD_SEQ_NUM>089938</CTD_SEQ_NUM>
<CTD_CTD_PKG_ID>345</CTD_CTD_PKG_ID>
<CTD_LANG_ID>E</CTD_LANG_ID>
</Table>
<Table>
<RECORD_TYPE_CODE>ITD</RECORD_TYPE_CODE>
<MSG_TYPE_CODE>O103</MSG_TYPE_CODE>
<CTD_SEQ_NUM>089939</CTD_SEQ_NUM>
<CTD_CTD_PKG_ID>345</CTD_CTD_PKG_ID>
<CTD_LANG_ID>E</CTD_LANG_ID>
</Table>
</NewDataSet>
i have written my xslt below
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no" omit-xml-declaration="yes" />
<xsl:param 开发者_Go百科name="PackageId" />
<xsl:template match="/">
<xsl:apply-templates select="NewDataSet/Table[CTD_CTD_PKG_ID ='345']"/>
</xsl:template>
<xsl:template match="NewDataSet/Table[CTD_CTD_PKG_ID ='345']">
<xsl:value-of select= "concat(':25:',./CTD_LANG_ID)"/>,<xsl:text/>
<xsl:if test ="./RECORD_TYPE_CODE" >
<xsl:if test=" position() > 1"></xsl:if>
<xsl:text/><xsl:value-of select= "concat(':20:',./RECORD_TYPE_CODE)" />,<xsl:text/>
</xsl:if>
<xsl:if test ="./MSG_TYPE_CODE" >
<xsl:if test=" position() > 1"></xsl:if>
<xsl:text/><xsl:value-of select= "concat(':21:',./MSG_TYPE_CODE)"/>,<xsl:text/>
</xsl:if>
<xsl:if test ="./CTD_SEQ_NUM" >
<xsl:if test=" position() > 1"></xsl:if>
<xsl:text/><xsl:value-of select= "concat(':22:',./CTD_SEQ_NUM)"/>,<xsl:text/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
current output for this above xslt
:25:E,:25:E,
Expected output= :25:E,
If you are using such specific IDs, a simple way to do this would be to simply select the first TABLE with the matching ID using the position() function, like so
<xsl:apply-templates select="NewDataSet/Table[CTD_CTD_PKG_ID ='345'][position()=1]"/>
Note that, you can actually simplify the template match by just matching on Table if required. Here is the whole XSLT in this case
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no" omit-xml-declaration="yes"/>
<xsl:param name="PackageId"/>
<xsl:template match="/">
<xsl:apply-templates select="NewDataSet/Table[CTD_CTD_PKG_ID ='345'][position()=1]"/>
</xsl:template>
<xsl:template match="Table">
<xsl:value-of select="concat(':25:',./CTD_LANG_ID)"/>,
<xsl:text/></xsl:template>
</xsl:stylesheet>
When applied on your input XML, the result is as follows:
:25:E,
精彩评论