如何在XSL中定义HTML标签里的属性使用XSL的值??
[xml]
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="exam.xsl"?> <test> <test_type>exam</test_type> <testid id="1"> <say>什么事情啊?</say> <answers> <answer id="00001">我知道了</answer> <answer id="00002">我明白了</answer> <answer id="00003">是的</answer> <answer id="00004">好</answer> </answers> </testid> <testid id="2"> <say>什么事情啊?2</say> <answers> <answer id="00001">我知道了2</answer> <answer id="00002">我明白了2</answer> <answer id="00003">是的2</answer> <answer id="00004">好2</answer> </answers> </testid> <testid id="3"> <say>什么事情啊?3</say> <answers> <answer id="00001">我知道了3</answer> <answer id="00002">我明白了3</answer> <answer id="00003">是的3</answer> <answer id="00004">好3</answer> </answers> </testid> </test>
[exam.xsl]
<?xml version=‘1.0‘ encoding=‘utf-8‘ ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output method="html"/> <xsl:template match="/"><form action="test.aspx" method="post"> <p><xsl:apply-templates select="test"/></p> <p> <input type="submit" value="Submit"/> <input type="reset" value="Reset"/> </p> </form> </xsl:template> <xsl:template match="test"> <xsl:for-each select="testid"> <p>题目: </p> <xsl:value-of select="say"/> <xsl:for-each select="answers"> <xsl:for-each select="answer"> <p> <input type="radio" CHECKED="0" value="text()" name="ancestor::testid/@id" > <xsl:value-of select=" text()"/> </input> </p> </xsl:for-each> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet>
语法:
name="{ancestor::testid/@id}"
原文地址:https://www.cnblogs.com/demonxian3/p/9151945.html
时间: 2024-10-08 01:19:49