XSL输出方法文本,包括xsl中的空格 [英] XSL output method text including whitespaces in xsl

查看:282
本文介绍了XSL输出方法文本,包括xsl中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一些xsl来将我的xml转换为文本(最终将是csv).我正在使用VS2008.当我使用编辑器创建xsl时,按照我的xsl缩进转换后的输出.但是,如果我编辑xsl并删除格式化的空格,则它可以正确输出-但是这样做是一场噩梦.

I am creating some xsl to transform my xml into text (which will be csv eventually). I am using VS2008. When I use the editor to create the xsl, the transformed output is indented as per my xsl. However, if I edit the xsl and remove the formatted whitespaces it outputs correctly - but doing it like this is a nightmare to work with.

我可以插入一些xsl预处理程序命令或标记来防止这种情况吗?我想忽略xsl中的任何空格,而只使用<!CDATA[]]><xsl:text>输出文本.

Is there some xsl pre-processor commands or markup I can put in to prevent this? I want to ignore any whitespace in my xsl and only output text using <!CDATA[]]> or <xsl:text>.

我的XSL如下-缩进输出

My XSL is as below - this indents the output

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="text" indent="no"/>
  <!-- @* is all class attributes -->
  <xsl:template match="/">
    <xsl:text>CSV Output</xsl:text>
    <!-- Start of output -->
    <xsl:for-each select="//rows/row">
      <![CDATA[row id=]]><xsl:value-of select="(@id)"/>
    </xsl:for-each>
    <!-- OK, that is the end of the file -->
    <![CDATA[<EOF>]]>
  </xsl:template>
</xsl:stylesheet>

其输出如下:

CSV Output
      row id=0
      row id=1
    <EOF>

但是,以下输出正确:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="text" indent="no"/>
  <!-- @* is all class attributes -->
  <xsl:template match="/">
    <xsl:text>CSV Output</xsl:text>
    <!-- Start of output -->
    <xsl:for-each select="//rows/row">
<![CDATA[row id=]]><xsl:value-of select="(@id)"/>
</xsl:for-each>
<!-- OK, that is the end of the file -->
<![CDATA[<EOF>]]>
  </xsl:template>
</xsl:stylesheet>

这正确地输出如下:

CSV Output
row id=0
row id=1
<EOF>

我还想控制新行的位置.在我的xsl中,我没有告诉它包含一个.

I also want to control where a new line is included. In my xsl I am not telling it to include one.

请帮助!

谢谢

安德兹(Andez)

推荐答案

XSLT处理器仅在XSLT元素之间剥离模板中的空白文本节点.

The XSLT processor strips white-space text nodes in the template only between XSLT elements.

所以,在

<xsl:for-each select="//rows/row"> 
  <![CDATA[row id=]]><xsl:value-of select="(@id)"/> 
</xsl:for-each>

xsl:for-each元素有两个空格文本子节点:一个在xsl:value-of之后,被剥离;另一个在xsl:value-of之后,被剥离.另一个在CDATA部分之前,未剥离.

the xsl:for-each element has two white-space text child nodes: One after xsl:value-of, which is stripped; the other before the CDATA section, which is not stripped.

底线:使用xsl:text元素.

<xsl:for-each select="//rows/row"> 
  <xsl:text><![CDATA[row id=]]></xsl:text>
  <xsl:value-of select="@id"/> 
</xsl:for-each>

这篇关于XSL输出方法文本,包括xsl中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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