Xml 需要检索当前元素
我正在尝试获取当前元素节点,但我只获取元素的值。请帮帮我Xml 需要检索当前元素,xml,xslt,Xml,Xslt,我正在尝试获取当前元素节点,但我只获取元素的值。请帮帮我 <root><LIST> <ROLE>s1</ROLE> <STATUS>yes</STATUS> </LIST> <LIST> <ROLE>s1&
<root><LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>yes</STATUS>
</LIST>
</root>
s1
对
s1
对
成员
不
成员
不
成员
对
我试着
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"><html>
<h2>
<xsl:element name="test">
<xsl:for-each select="/root/LIST[STATUS='yes']">
<xsl:copy-of select="current()"/>
</xsl:if>
</xsl:for-each>
</xsl:element>
</h2></html>
</xsl:template>
</xsl:stylesheet>
但是我只得到元素的值。我需要用值检索当前元素。有没有人想到使用
<xsl:copy-of select="."/>
并删除不匹配的xsl:if like so
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<h2>
<xsl:element name="test">
<xsl:for-each select="/root/LIST[STATUS='yes']">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:element>
</h2>
</html>
</xsl:template>
</xsl:stylesheet>
结果将是
<html>
<h2><test><LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST><LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST><LIST>
<ROLE>Member</ROLE>
<STATUS>yes</STATUS>
</LIST>
</test>
</h2>
</html>
s1
对
s1
对
成员
对
使用
<xsl:copy-of select="."/>
并删除不匹配的xsl:if like so
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<h2>
<xsl:element name="test">
<xsl:for-each select="/root/LIST[STATUS='yes']">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:element>
</h2>
</html>
</xsl:template>
</xsl:stylesheet>
结果将是
<html>
<h2><test><LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST><LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST><LIST>
<ROLE>Member</ROLE>
<STATUS>yes</STATUS>
</LIST>
</test>
</h2>
</html>
s1
对
s1
对
成员
对
这是一种相当奇怪的说法:
<test>
<xsl:copy-of select="/root/LIST[STATUS='yes']"/>
</test>
因此,完整的转换可以是这样的:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<html>
<h2>
<test>
<xsl:copy-of select="/root/LIST[STATUS='yes']"/>
</test>
</h2>
</html>
</xsl:template>
</xsl:stylesheet>
<root>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>yes</STATUS>
</LIST>
</root>
在提供的XML文档上应用此转换时:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<html>
<h2>
<test>
<xsl:copy-of select="/root/LIST[STATUS='yes']"/>
</test>
</h2>
</html>
</xsl:template>
</xsl:stylesheet>
<root>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>yes</STATUS>
</LIST>
</root>
s1
对
s1
对
成员
不
成员
不
成员
对
生成所需的正确结果:
<html>
<h2>
<test>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>yes</STATUS>
</LIST>
</test>
</h2>
</html>
s1
对
s1
对
成员
对
这是一种相当奇怪的说法:
<test>
<xsl:copy-of select="/root/LIST[STATUS='yes']"/>
</test>
因此,完整的转换可以是这样的:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<html>
<h2>
<test>
<xsl:copy-of select="/root/LIST[STATUS='yes']"/>
</test>
</h2>
</html>
</xsl:template>
</xsl:stylesheet>
<root>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>yes</STATUS>
</LIST>
</root>
在提供的XML文档上应用此转换时:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<html>
<h2>
<test>
<xsl:copy-of select="/root/LIST[STATUS='yes']"/>
</test>
</h2>
</html>
</xsl:template>
</xsl:stylesheet>
<root>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>no</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>yes</STATUS>
</LIST>
</root>
s1
对
s1
对
成员
不
成员
不
成员
对
生成所需的正确结果:
<html>
<h2>
<test>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>s1</ROLE>
<STATUS>yes</STATUS>
</LIST>
<LIST>
<ROLE>Member</ROLE>
<STATUS>yes</STATUS>
</LIST>
</test>
</h2>
</html>
s1
对
s1
对
成员
对
如果我按预期删除输出(包括标记),则您的xslt无效。。您想要的输出是什么?很抱歉,我发布了错误的代码。现在我更新了代码。但是,我得到的是单独的值,而不是元素。与您期望的有什么不同?如果我按预期删除输出(包括标记),您的xslt将无效。。您想要的输出是什么?很抱歉,我发布了错误的代码。现在我更新了代码。但我得到的是单独的值,而不是元素。与您期望的有什么不同?