如何按 顺序读xml文档 (???使position()= 后面的值为变量且可以自增 )
xml文档如下:名称为ppacd.xml
<?xml version= "1.0 " encoding= "GB2312 "?>
<catalog>
<cd>
<NAME> 姓名 </NAME>
<cid id= "name "> name </cid>
</cd>
<cd>
<NAME> 性别 </NAME>
<cid id= "name2 "> sex </cid>
</cd>
<cd>
<NAME> 年龄 </NAME>
<cid id= "name2 "> age </cid>
</cd>
<cd>
<NAME id= "name2 "> 籍贯 </NAME>
<cid> native </cid>
</cd>
</catalog>
xslt:代码如下:
<?xml version= "1.0 " encoding= "GB2312 "?>
<xsl:stylesheet version= "1.0 "
xmlns:xsl= "http://www.w3.org/1999/XSL/Transform ">
<xsl:output method= "html "/>
<xsl:param name= "ppacd.xml "/>
<xsl:template match= "*|@*|text() ">
<xsl:copy>
<xsl:apply-templates select= "*|@*|text() "/>
</xsl:copy>
</xsl:template>
<xsl:variable name= "ppacd " select= "document( 'ppacd.xml ') "/>
<xsl:variable name= "i " select= "0 "/>
<xsl:template match= "td ">
<xsl:copy>
<xsl:copy-of select= "@* "/>
<xsl:choose>
<xsl:when test= "(position()div 2)mod 2 = 1 ">
<span>
<xsl:attribute name= "id ">
<xsl:variable name= "QQ " select= "document( 'ppacd.xml ')/catalog/cd/cid/@value "/>
<xsl:variable name= "span " select= "concat(document( 'ppacd.xml ')/catalog/cd/cid, 'language ') "/>
<xsl:value-of select= "$span "/>
</xsl:attribute>
<xsl:value-of select= "document( 'ppacd.xml ')/catalog/cd/cid "/>
</span>
</xsl:when>
<xsl:when test= "(position()div 2)mod 2 = 0 ">
<input type= "text ">
<xsl:attribute name= "id ">
<xsl:value-of select= "document( 'ppacd.xml ')/catalog/cd/cid "/>
</xsl:attribute>
<xsl:attribute name= "name ">
<xsl:value-of select= "document( 'ppacd.xml ')/catalog/cd/*[@id= 'name '] "/>
</xsl:attribute>
</input>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
这句代码只能取到name
<xsl:value-of select= "document( 'ppacd.xml ')/catalog/cd/cid "/>
如何实现第一次取name
2次取sex
3次取age
如此类推 谢谢
如果用这个方法
<xsl:value-of select= "document( 'ppacd.xml ')/catalog/cd/cid[position()= '一个自增的变量 ' "/> 怎么做到 或者有其他的方法 谢谢了
[解决办法]
http://dotnet.aspx.cc/article/4052da03-51e0-464b-8418-3c1354920f8f/read.aspx
[解决办法]
嵌入javascript处理比较好