从web.config获取价值到XSLT文件中 [英] Get value from web.config into XSLT file
问题描述
我的Web.config中有一些要在XSLT文件中访问的值.我该怎么办?
I have some values in my web.config that I want to access in my XSLT file. How do I do that?
我这样做是为了将配置文件加载到我的XSLT中:
I have done this to load the config file in my XSLT:
<xsl:variable name="config" select="document('..//Website//web.config')"/>
<p><xsl:value-of select="$config//appSettings/add[@key='Test']/@value"/>
</p>
在此之后,我被卡住了-什么也没渲染.
After this I am stuck - nothing gets rendered.
好的.我做了一些更改.我尝试使用一个单独的XML文件,并且能够从该文件的变量中获取值.
Ok.I have done some changes.I have tried using a separate XML file and i am able to get value from the file in my variable.
<xsl:apply-templates select="document('TestXML.xml')/test/Tag1">
</xsl:apply-templates>
<xsl:template match="Tag1">
<xsl:choose>
<xsl:when test="@sName='myTest'">
<span>
<xsl:value-of select="@TestId" />
</span>
</xsl:when>
</xsl:choose>
</xsl:template>
我仍然感到困惑,即在读取web.config文件(这是一个xml文件)时,我得到了一个空变量,但是对于纯.xml文件,我在我的变量中得到了一个值.
I am still confused that while reading the web.config file(which is an xml file), i get an empty variable, but for a pure .xml file i get a value in my variable.
我的Test.XML是这个
my Test.XML is this
<?xml version="1.0"?>
<test>
<Tag1 sName="myTest" TestId="328,329">
</Tag1>
</test>
请帮助我如何使用<appsettings>
部分下的值的Web.config文件.
Please help me as to how could i work with a Web.config file with values under <appsettings>
section.
推荐答案
document()
函数应接收有效的URI方案. XPath中使用双斜杠//
,但在URI中不是有效的路径分隔符.如果您的web.config
文件位于Website
目录中,该目录是XSLT所在目录的同级文件,则语法应为:
The document()
function should receive a valid URI scheme. Double-slashes //
are used in XPath but are not valid path separators in an URI. If your web.config
file is in the Website
directory which is a sibling of the directory where your XSLT is located, the syntax should be:
<xsl:variable name="config" select="document('../Website/web.config')"/>
假设样式表的其余部分正确无误,并且web.config
中XML的结构与之匹配,则value-of
中的XPath表达式应该可以工作.
Assuming the rest of your stylesheet is correct, the XPath expression in the value-of
should work if the structure of the XML inside your web.config
matches it.
这篇关于从web.config获取价值到XSLT文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!