how to change xml by browser

匆匆过客 提交于 2020-01-23 18:03:33

问题


I would like to change some rules in my XML depending on the browser. For example, the 'fontcolor' should be black when using IE. So far I googled it, I found this could be possible using XSLT. But unfortunately, after googling/trying&error after 1/2 days, I still didn't get the clue how to do this.

Could someone help me how to solve this? Any help would be highly appreciated. Thanks !!

EetieD.

My current XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<skin version='1.1' name='player' author='me'>
    <components>
        <component name='control'>
            <settings>
                <setting name='fontsize' value='10' />
                <setting name='fontcolor' value='0xffffff' /> <!-- if IE: 0x000000-->
                //.....

My current XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- .... -->
<xsl:template match="/">
  <xsl:comment>
    <![CDATA[[if !IE]>show non-iE text<![endif]]]>
  </xsl:comment>

</xsl:template>

</xsl:stylesheet>

回答1:


I don't think there is a good way to detect browsers using only XSLT. Although XSLT was originally designed to be executed on XML in-browser, that's not how it worked out in practice. I think you'll be better off doing your browser detection in Javascript.

From there, you could conditionally output the XML you want directly from the JavaScript, or you could pass the browser type as an external variable to your XSLT and let it handle the conditional logic.



来源:https://stackoverflow.com/questions/13274529/how-to-change-xml-by-browser

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