c# - 当属性具有'@'时如何在 XSL 中获取值
问题描述
如何在下面的XSL文件中获取<xsl>
元素的值?'maa'
<xsl:stylesheet version="3.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eu="http://europa.eu.int" xmlns:xlink="http://www.w3c.org/1999/xlink">
<xsl:template mode="agency">
<xsl:choose>
<xsl:when test="@code='AT-BASG'">Austria - BASG- Austrian Federal Office for Safety in Health Care / Austrian Medicines and Medical Devices Agency</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template mode="submission">
<xsl:choose>
<xsl:when test="@type='maa'">Marketing Authorisation</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
我尝试如下:
string emp = "@type='maa'";
XmlDocument xslDoc = new XmlDocument();
xslDoc.Load(IndexFTPLocation);
//ReadXElement(indexXele, sequenceName, ApplicationName, IndexFTPLocation, 1);
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xslDoc.NameTable);
nsMgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
XmlNode usrNode = xslDoc.SelectSingleNode("/xsl:stylesheet/xsl:template[@mode='submission']/xsl:choose/xsl:when[@test='@type='maa'']", nsMgr);
但是,当 type="maa" 时,我无法获得“营销授权”。你能帮我解决这个问题吗?
提前致谢!!
编辑: 出现错误:'/xsl:stylesheet/xsl:template[@mode='submission']/xsl:choose/xsl:when[@test='@type='maa'']' 具有无效标记。
解决方案
您可以使用in"
代替,如以下代码:'
xsl:when[@test='@type='maa'']
XmlDocument xslDoc = new XmlDocument();
xslDoc.Load(IndexFTPLocation);
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xslDoc.NameTable);
nsMgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
XmlNode usrNode = xslDoc.SelectSingleNode("/xsl:stylesheet/xsl:template[@mode='submission']/xsl:choose/xsl:when[@test=\"@type='maa'\"]", nsMgr);
string text = usrNode?.InnerText;
演示
Console.WriteLine(text);
结果
Marketing Authorisation
我希望你觉得这有帮助。
推荐阅读
- flutter - 根据用户角色显示/隐藏小部件
- java - jdk和gradle问题
- database-migration - 如何有条件地运行 Knex 迁移
- laravel - 无法在 laravel 7.5.2 上安装 vue ui
- javascript - ReactJS:当其中的文本为某个值时如何使按钮背景颜色发生变化
- inno-setup - 如何在 Inno Setup 中更改窗口标题中的名称?
- python - 如何使用 python 子进程模块执行多个 shell 命令?
- javascript - jQuery如何实现CRUD操作?
- javascript - 如何理解以下代码中的解构语法
- java - 从数组返回流作为 int[] 而不是 Integer[]