【求助】去除解析过程中产生的多余换行符

Carignano 2008-01-29 01:55:50
我使用xsl文件去解析一个xml
从而得到一些数据
但是在解析过程中我发现会很有多的换行符产生
也就是说,原来可以放在一行中的数据会被分成多行
这样会使数据量加大
请问有什么方法可以去除这些多余的换行符(在xsl文件中修改的方法)
...全文
302 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
tantaiyizu 2008-01-30
  • 打赏
  • 举报
回复
[]
Carignano 2008-01-30
  • 打赏
  • 举报
回复
这个问题我再研究研究,谢谢各位
Carignano 2008-01-29
  • 打赏
  • 举报
回复
我写的全一点好了
xml中
<items>
<item id="a">abc</item>
<item id="b">ddd</item>
<item id="c">eee</item>
</items>

xsl中
<xsl:template match="items">var _b = {<xsl:apply-templates mode="k"/>};</xsl:template>
<xsl:template mode="k" match="item"><xsl:if test="position()!=2">,</xsl:if><xsl:value-of select="@id"/>:'<xsl:value-of select="."/>'</xsl:template>

输出结果就是
var _b = {
a: 'abc'
,b: 'ddd'
,c: 'eee'
};

这个不就是换行了嘛
我想要它输出在一行里面,变成 var _b = {a: 'abc', b: 'ddd', c: 'eee'};
这个可以通过抓包或者其他比如firebug看到真正response的数据
请帮忙
孟子E章 2008-01-29
  • 打赏
  • 举报
回复
DOM查看器是换行的
你可以这样

<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<xsl:for-each select="data/item">
<xsl:call-template name="item" />
</xsl:for-each>
</html>
</xsl:template>
<xsl:template name="item">xxx<xsl:value-of select="."/></xsl:template>
</xsl:stylesheet>
孟子E章 2008-01-29
  • 打赏
  • 举报
回复
没有出现你说的现象

<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="1.xsl"?>
<data>
<item>a</item>
<item>b</item>
<item>c</item>
</data>




<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<xsl:apply-templates select="data" mode="data"/>
</html>
</xsl:template>
<xsl:template mode="data" match="item">xxx<xsl:value-of select="."/></xsl:template>
</xsl:stylesheet>
Carignano 2008-01-29
  • 打赏
  • 举报
回复
不是不是,我知道你们的那个问题
ie显示出来的是它自己排版过的,如果你使用查看源代码可以发现真正传输时候的格式
我用firefox的firebug调试时候看到的,content-length是有不同的
tantaiyizu 2008-01-29
  • 打赏
  • 举报
回复
你浏览器的问题吧
xiaolei1982 2008-01-29
  • 打赏
  • 举报
回复
我测试过的
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<xsl:apply-templates select="recipes/item"/>
</html>
</xsl:template>
<xsl:template match="item">xxx<xsl:value-of select="."/></xsl:template>
</xsl:stylesheet>

浏览:1.xml
结果:xxxaxxxbxxxc
Carignano 2008-01-29
  • 打赏
  • 举报
回复
13楼输出的就是
xxxa
xxxb
xxxc

这个么就出来换行啦
我要的就是不要换行。。。
我需要输出
xxxaxxxbxxxc

怎么办?
tantaiyizu 2008-01-29
  • 打赏
  • 举报
回复
如果要显示在table中 ,怎么办?
xiaolei1982 2008-01-29
  • 打赏
  • 举报
回复
[code=HTML]<?xml version="1.0" encoding="gb2312"?> 
<?xml-stylesheet type="text/xsl" href="1.xsl"?>
<recipes>
<item id='1'>a</item>
<item id='2'>b</item>
<item id='3'>c</item>
</recipes>

[/code]

<?xml version="1.0" encoding="gb2312" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">  <xsl:template match="/"> 
<html>
<xsl:apply-templates select="recipes/item"/>
</html>
</xsl:template>
<xsl:template match="item">xxx<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
Carignano 2008-01-29
  • 打赏
  • 举报
回复
还有就是我意思是结合后出来的其实是个js文件
我就是为了读取上更快速,所以不想有多余的换行
因为这样会增加文件大小
Carignano 2008-01-29
  • 打赏
  • 举报
回复
不是用的httprequest
就是一个xml一个xsl
xiaolei1982 2008-01-29
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="gb2312"?>
<recipes>
<item id='1'>a</item>
<item id='2'>b</item>
<item id='3'>c</item>
</recipes>



<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<xsl:apply-templates select="recipes/item"/>
</html>
</xsl:template>
<xsl:template match="item">xxx<xsl:value-of select="."/></xsl:template>
</xsl:stylesheet>


<
html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body onload="init();">
</body>
</html>

<script >
function init(){
//alert(parent.frames.length); alert(parent.frames[0].name); alert(parent.frames[1].name); alert(parent.frames[2].name);
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("1.xml")
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("1.xsl")
GuidContent.innerHTML = xml.transformNode(xsl);
}
</script>
<div id="GuidContent"></div>
Carignano 2008-01-29
  • 打赏
  • 举报
回复
给个例子好么?
xsl我是门外汉
tantaiyizu 2008-01-29
  • 打赏
  • 举报
回复
怎么不用 div去选择呢?
Carignano 2008-01-29
  • 打赏
  • 举报
回复
我在xsl里面写的
<xsl:apply-templates mode="data"/>
<xsl:template mode="data" match="item">xxx <xsl:value-of select="."/></xsl:template>
就是这样呀
然后么就出来
xxxa
xxxb
xxxc

其实我要的是xxxaxxxbxxxc
一行里面的
tantaiyizu 2008-01-29
  • 打赏
  • 举报
回复
让看看你怎么解析的 ,选的什么标签
Carignano 2008-01-29
  • 打赏
  • 举报
回复
我其实是想把解析出来的变成一个js文件
就比如说xml里面
<item id='1'>a</item>
<item id='2'>b</item>
<item id='3'>c</item>
我在xsl里面
建立了一个item的template,但是呢

出来以后就变成了
xxxa
xxxb
xxxc
其实我不想让他换行的
我最好能在一行里面显示出来
问题就出现了
xiaolei1982 2008-01-29
  • 打赏
  • 举报
回复
解析应该不会出现换行符的,除非刻意加上换行符,
或许是你在解析出来后,其他的原因造成换行
加载更多回复(3)
PowerBI系列之Power Query专题1.  获取数据 数据源种类介绍和获取Excel数据源输入数据和拷贝数据:创建辅助表解析Json/XML数据格式获取Web网页数据和URL添加动态参数连接数据的四种模式:Import、DirectQuery、Live Connection、Dual双 属于混合模式连接数据库:Sql server、 Mysql(直连但是必须先安装一个mysql插件)DirectQuery直连查询:Sql serverODBC方式获取数据表关联或多个Sql或调用存储过程获取数据SQL动态传参和自定义函数: sql使用参数或数据库名称使用参数连接Sharepoint和OneDrive数据源连接Dataset和Dataflow 替换本地数据源为Sharepoint数据源并保留数据处理操作 终止当前数据刷新Loading:Cancel Query数据源设置-重置数据连接凭证PBIDS连接数据源创建和使用报表模块(输入或值列表)利用报表模板和参数控制线下报表数据权限DirectQuery启用自动页面刷新和更改检测管理聚合表提高DirectQuery查询性能动态M查询参数提高DirectQuery查询性能添加数据刷新时间 DateTime.LocalNow()和Getdate()2.  数据清洗和M语言M语言和官方文档介绍PowerQuery查阅M函数:=#shared, Ctrl+Space提示数据清洗之常用技能:提升标题、更改数据类型、保留删除错误或空行,删除重复项、选择列和删除列、填充单元格、合并列、拆分、提取、替换、条件替换、添加自定义列,添加条件列、添加索引列、分组、添加年月日列、追加和合并查询透视和逆透视以及转置合并单元格的Excel文件处理导入文件夹多Excel文件并合并解决多文件合并列顺序不一致使用参数和函数批量导入文件 文本提取文、英文、数字等处理双引号转义 列拆分详解解决列名改变错误解决列丢失错误动态显示、排序和重命名列为所有列名添加前缀列名字母大写和分隔符调整Trim标题列多余空格如何处理load数据错误为什么load的Excel数据有null空行为什么load的Excel数据标题在第二行灵活添加占位符规范同类相似数据数据按多列排序为分组添加Index序号分组内值合并诊断工具分析数据处理过程PowerQuery小技巧分享 新冠病例活动轨迹地图标识 

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧