如何通过浏览器更改的XML [英] how to change xml by browser

查看:227
本文介绍了如何通过浏览器更改的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想取决于浏览器来改变我的XML的一些规则。例如,使用IE当'FONTCOLOR'应该是黑色的。到目前为止,我GOOGLE了它,我发现这个可以使用XSLT是可能的。但不幸的是,谷歌搜索/试图与放后;后1/2天的错误,我仍然没有得到线索如何做到这一点。

有人能帮助我如何解决这个问题?任何帮助将是非常美联社preciated。谢谢!

EetieD。

我目前的XML:

 <?XML版本=1.0编码=ISO-8859-1&GT?;
<?xml样式表类型=文/ XSL的href =test.xsl&GT?;
<皮肤版本=1.1NAME ='玩家'作家='我'>
    <成分>
        <成分名称='控制'>
            <设置>
                <设定名='字号'值= '10'/>
                <设定名='FONTCOLOR'值='0XFFFFFF/> < - 如果IE:0x000000处 - >
                // .....

我目前的XSL:

 <?XML版本=1.0编码=ISO-8859-1&GT?;
<的xsl:样式版本=1.0
的xmlns:XSL =htt​​p://www.w3.org/1999/XSL/Transform>
<! - ... - >
<的xsl:模板匹配=/>
  < XSL:评论>
    <![!CDATA [[如果IE>显示非IE文字<![ENDIF]]]>
  < / XSL:评论>< / XSL:模板>< / XSL:样式>


解决方案

我不认为这是只使用XSLT来检测浏览器的好方法。虽然XSLT的最初目的是要在浏览器内执行XML,这不是它如何在实践中摸索出。我想你会更好做你的浏览器检测在Javascript

从那里,你可以有条件地输出XML直接从JavaScript的希望,或者你可以通过浏览器类型为外部变量到你的XSLT,让它处理条件逻辑。

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>

解决方案

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.

这篇关于如何通过浏览器更改的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆