Get value from web.config into XSLT file

我与影子孤独终老i 提交于 2019-12-11 08:59:03

问题


I have some values in my web.config that I want to access in my XSLT file. How do I do that?

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.

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>

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.

my Test.XML is this

<?xml version="1.0"?>
<test>
  <Tag1 sName="myTest" TestId="328,329">
  </Tag1>

</test>

Please help me as to how could i work with a Web.config file with values under <appsettings> section.


回答1:


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')"/>

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.



来源:https://stackoverflow.com/questions/23826017/get-value-from-web-config-into-xslt-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!