|
以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 DOM/SAX/XPath 』 (http://bbs.xml.org.cn/list.asp?boardid=11) ---- 如何按 顺序读xml文档 (???使position()= 后面的值为变量且可以自增 ) (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=43773) |
|
-- 作者:pope3618 -- 发布时间:3/9/2007 2:17:00 PM -- 如何按 顺序读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 如此类推 谢谢 如果后面加个position并赋值如何做 :<xsl:value-of select="document('ppacd.xml')/catalog/cd/cid[position()=i++]"/> 这样的功能如何实现 |
|
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
46.875ms |