我有以下XML文件之类的内容。我需要使用XSL获取成员名称。
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="styleSheet.xsl"?>
<doc>
<assembly>
<name>AlienRFID2</name>
</assembly>
<members>
<member name="T:nsAlienRFID2.AlienDataDirector">
<summary>
EXPERIMENTAL. Objects of this class may be used for sending Alien reader's messages to an external listener.
Typical use of this class is by a mobile device, which is listening for Alien reader's notifications using CAlienServer objects and
wants to transfer those to a host (target) computer.
</summary>
</member>
<member name="M:nsAlienRFID2.AlienDataDirector.#ctor(System.Int32,System.Net.IPAddress,System.Boolean)">
<summary>
Creates instance for connecting to specified host server.
</summary>
<param name="targetPort">Network port value for connecting to host (target.)</param>
<param name="targetIPAddress">IPAddress value for connecting to host (target.)</param>
<param name="log">TRUE for turning internal API logging ON, FALSE otherwise.</param>
</member>
</members>
</doc>
我需要吐出't:nsalientfrid2.alien ...'和'm; nsalienrfid2.alien ...'"成员名称"字符串"到浏览器。我明白它的内容类似于XSL:select select =" member/@name",但我无法对此进行任何变化。而且我找不到一个清晰的示例,说明如何在引号中获得属性。有人可以帮我一个例子吗?谢谢!
编辑..我当前正在尝试此代码,但它吐出了摘要,而不是属性"名称"。
<xsl:for-each select = "doc/members/member">
<xsl:value-of select = "@name"/>
</xsl:for-each>
您可以使用此样式表名为 styleSheet.xsl
匹配元素,然后使用 xsl:value-of
获取属性的值:
<?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" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="doc/members/member">
<xsl:value-of select="@name" /><br />
</xsl:template>
<!-- suppress other text nodes -->
<xsl:template match="text()" />
</xsl:stylesheet>
然后您可以按照自己的方式格式化输出。
输出:
T:nsAlienRFID2.AlienDataDirector
M:nsAlienRFID2.AlienDataDirector.#ctor(System.Int32,System.Net.IPAddress,System.Boolean)