从外部XML文件输出
我创建了一个xsl文件,它将输出两个XML:s 其中一个xml应该只收获一次。因为它只有一个结构,而且工作正常,所以我不会发布代码, 但另一个我想输出整个树结构。但它只打印第一张。而不是整棵树 这就是我目前的打算从外部XML文件输出,xml,xslt,Xml,Xslt,我创建了一个xsl文件,它将输出两个XML:s 其中一个xml应该只收获一次。因为它只有一个结构,而且工作正常,所以我不会发布代码, 但另一个我想输出整个树结构。但它只打印第一张。而不是整棵树 这就是我目前的打算 <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="$doc1//quiz//question">
<xsl:value-of select="$doc1//author" />
<br />
<xsl:value-of select="$doc1//questionText" />
<br />
<xsl:text>Ger </xsl:text><xsl:value-of select="$doc1//points" /><xsl:text> Poäng </xsl:text>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
格尔波昂
谢谢
编辑:
将ad我的XML文件
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="q2.xsl"?>
<quiz>
<question>
<author>Författare 1</author>
<questionText>Fråga 1</questionText>
<correct>Svar 1</correct>
<incorrect>fel 1</incorrect>
<incorrect>fel 1-2</incorrect>
<points>1</points>
</question>
<question>
<author>Författare 2</author>
<questionText>Fråga 2</questionText>
<correct>Svar 2</correct>
<incorrect>fel 2</incorrect>
<incorrect>fel 2-3</incorrect>
<points>2</points>
</question>
<question>
<author>Författare 3</author>
<questionText>Fråga 3</questionText>
<correct>Svar 3</correct>
<incorrect>fel 3</incorrect>
<incorrect>fel 3-4</incorrect>
<points>3</points>
</question>
<question>
<author>Författare 4</author>
<questionText>Fråga 4</questionText>
<correct>Svar 4</correct>
<incorrect>fel 4</incorrect>
<incorrect>fel 4-5</incorrect>
<points>4</points>
</question>
<question>
<author>Författare 5</author>+
<questionText>Fråga 5</questionText>
<correct>Svar 5</correct>
<incorrect>fel 5</incorrect>
<incorrect>fel 5-6</incorrect>
<points>5</points>
</question>
</quiz>
Författare 1
弗雷加1
Svar 1
自由电子激光器1
自由电子激光器1-2
1.
费尔法塔雷2号
弗雷加2
Svar 2
自由电子激光器2
自由电子激光器2-3
2.
Författare 3
弗雷加3
SVAR3
自由电子激光器3
自由电子激光器3-4
3.
Författare 4
弗雷加4
SVAR4
自由电子激光器4
自由电子激光器4-5
4.
Författare 5+
Fråga 5
Svar 5
自由电子激光器5
自由电子激光器5-6
5.
您的问题是,当您为每个语句输入时,您将引用回原始的$doc
,而不是实际的上下文节点
这应该行得通
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="$doc1/quiz/question">
<xsl:value-of select="author" />
<br />
<xsl:value-of select="questionText" />
<br />
<xsl:text>Ger </xsl:text><xsl:value-of select="points" /><xsl:text> Poäng </xsl:text>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
格尔波昂
使用应用模板的额外示例强>
这对阅读ect更好。一旦事情变得复杂,你可以很容易地注意到节点集的上下文
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="$doc1/quiz/question"/>
</body>
</html>
</xsl:template>
<xsl:template match="question">
<xsl:value-of select="author" />
<br />
<xsl:value-of select="questionText" />
<br />
<xsl:text>Ger </xsl:text>
<xsl:value-of select="points" />
<xsl:text> Poäng </xsl:text>
</xsl:template>
</xsl:stylesheet>
蒙古包
波昂
你能添加你的xml吗?那么提供一个解决方案可能会更容易。哦,我的天,谢谢你为此奋斗了将近一个小时:)欢迎你,而不是每一个你都可以使用apply templates match=“blah”然后创建一个新模板来匹配我将添加一个示例实际上刚刚开始尝试:)谢谢:)酷,stackoverflow上有一些xslt专家用户,因此如果您需要任何帮助,请不要害怕发布新问题!