以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  xml转换问题,求一个xslt文件  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=9755)


--  作者:菜籽
--  发布时间:9/4/2004 10:49:00 AM

--  xml转换问题,求一个xslt文件
有一个xml文件,我想把文件中的<TextBlock>与</TextBlock>之间的部分放到文本框中显示,并且各个文本框的名字不同,怎么实现啊,各位帮忙解决,谢谢,文件如下:
<Question ID="0" ZTMXH="0" KMDM="CCSJ0" TMLX="XZ0">
<QuestionPart XH="1">
  <TextBlock>题干</TextBlock>
</QuestionPart>
<AnswerPart xh="2" b_zqda="true" b_yc="false">
  <TextBlock>正确答案A</TextBlock>
</AnswerPart>
<AnswerPart xh="3" b_zqda="false" b_yc="false">
  <TextBlock>错误答案B</TextBlock>
</AnswerPart>
<AnswerPart xh="4" b_zqda="false" b_yc="false">
  <TextBlock>正确答案C</TextBlock>
</AnswerPart>
<AnswerPart xh="5" b_zqda="false" b_yc="false">
  <TextBlock>正确答案D</TextBlock>
</AnswerPart>
</Question>

--  作者:doubleG
--  发布时间:9/6/2004 5:50:00 PM

--  
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<head>
  <title></title>
</head>
<body>
<xsl:apply-templates select="Question"/>
</body>
</html>
</xsl:template>
<xsl:template match="Question">
 <xsl:apply-templates select="QuestionPart"/>
 <xsl:apply-templates select="AnswerPart"/>
</xsl:template>
<xsl:template match="QuestionPart">
 <input type="text" value="{TextBlock}" name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))"></input>
</xsl:template>
<xsl:template match="AnswerPart">
 <input type="text" value="{TextBlock}" name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))"/>
</xsl:template>
</xsl:stylesheet>
这个例子是把每个答案的最后一个字母作为了input text的name。
--  作者:菜籽
--  发布时间:9/6/2004 9:29:00 PM

--  
谢谢楼上的啊,好心人啊,再次对所有对小弟帮助的人表示由衷的感谢啊!
--  作者:菜籽
--  发布时间:9/7/2004 9:37:00 AM

--  
下面是输出结果,name属性好像不对啊,能不能实现几个text的名字是以相同的名字开头比如说answer而以数字结尾啊,形如answer1 ,answer2 的形式啊,再次谢谢2楼的好人
<html>
<head>
<title>
</title>
</head>
<body>
<input name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))" value="
asdasas" type="text"><input name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))" value="fdsadf
" type="text"><input name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))" value="
reygrt" type="text"><input name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))" value="
gwer" type="text"><input name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))" value="gwergwerg
" type="text">
</body>
</html>


--  作者:菜籽
--  发布时间:9/7/2004 9:38:00 AM

--  
<html>
<head>
<title>
</title>
</head>
<body>
<input name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))" value="asdasas" type="text">
<input name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))" value="fdsadf" type="text">
<input name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))" value="reygrt" type="text">
<input name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))" value="gwer" type="text">
<input name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))" value="gwergwerg" type="text">
</body>
</html>
--  作者:doubleG
--  发布时间:9/7/2004 9:51:00 AM

--  
name="substring(TextBlock,string-length(TextBlock),string-length(TextBlock))"——> name="{substring(TextBlock,string-length(TextBlock),string-length(TextBlock))}"
--  作者:doubleG
--  发布时间:9/7/2004 10:14:00 AM

--  
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="nameNum" select="0"/>
<xsl:template match="/">
<html>
<head>
  <title></title>
</head>
<body>
<xsl:apply-templates select="Question"/>
</body>
</html>
</xsl:template>
<xsl:template match="Question">
 <xsl:apply-templates select="QuestionPart"/>
 <xsl:apply-templates select="AnswerPart"/>
</xsl:template>
<xsl:template match="QuestionPart">
 <input type="text" value ="{TextBlock}" name="{concat('question',position())}"></input>
</xsl:template>
<xsl:template match="AnswerPart">
 <input type="text" value ="{TextBlock}" name="{concat('answer',position())}"/>
</xsl:template>
</xsl:stylesheet>
这样子是否满足要求啊?
--  作者:菜籽
--  发布时间:9/7/2004 12:03:00 PM

--  
先谢谢楼上的,由衷的感谢!好人
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
54.688ms