Xslt 删除xsl中的空白
我怎样才能去掉在破坏链接的“Location”元素之后添加的空间?IE:“/location toxxx.aspx” XMLXslt 删除xsl中的空白,xslt,whitespace,Xslt,Whitespace,我怎样才能去掉在破坏链接的“Location”元素之后添加的空间?IE:“/location toxxx.aspx” XML - <Root> <Schema> <Field Type="Text" DisplayName="Location" Required="FALSE" MaxLength="255" Name="Location" /> <Field Type="Currency" DisplayName="Price one way
- <Root>
<Schema>
<Field Type="Text" DisplayName="Location" Required="FALSE" MaxLength="255" Name="Location" />
<Field Type="Currency" DisplayName="Price one way-saloon" Required="FALSE" Decimals="0" LCID="2057" Name="Price_x0020_one_x0020_way" />
<Field Type="Currency" DisplayName="Price return-saloon" Required="FALSE" Decimals="0" LCID="2057" Name="Price_x0020_return" />
<Field ReadOnly="TRUE" Type="Computed" Name="LinkTitle" DisplayName="Location id" />
<Field Type="Currency" DisplayName="Price one way-estate" Required="FALSE" Decimals="0" LCID="2057" Name="Price_x0020_one_x0020_way_x002d_" />
<Field Type="Currency" DisplayName="Price return-estate" Required="FALSE" Decimals="0" LCID="2057" Name="Price_x0020_return_x002d_estate" />
<Field Type="Currency" DisplayName="Price one way-MPV" Required="FALSE" Decimals="0" LCID="2057" Name="Price_x0020_one_x0020_way_x002d_0" />
<Field Type="Currency" DisplayName="Price return-MPV" Required="FALSE" Decimals="0" LCID="2057" Name="Price_x0020_return_x002d_MPV" />
<Field Type="Currency" DisplayName="Price one way-MPV+" Required="FALSE" Decimals="0" LCID="2057" Name="Price_x0020_one_x0020_way_x002d_1" />
<Field Type="Currency" DisplayName="Price return-MPV+" Required="FALSE" Decimals="0" LCID="2057" Name="Price_x0020_return_x002d_MPV_x00" />
</Schema>
<Data ItemCount="1">
<Row Location="" Price_x0020_one_x0020_way="" Price_x0020_return="" LinkTitle="" Price_x0020_one_x0020_way_x002d_="" Price_x0020_return_x002d_estate="" Price_x0020_one_x0020_way_x002d_0="" Price_x0020_return_x002d_MPV="" Price_x0020_one_x0020_way_x002d_1="" Price_x0020_return_x002d_MPV_x00="" />
</Data>
</Root>
-
XSL
抱歉,如果我没有正确发布代码,如果我在换行符中留下,它会删除部分 至少有三种不同的方法:
<li>
<a>
<xsl:attribute name="href"
select="concat(@Location, 'toheathrow.aspx')"/>
<xsl:value-of select = "@Location" />
</a>
</li>
<li>
<a href="{@Location}toheathrow.aspx">
<xsl:value-of select = "@Location" />
</a>
</li>
.3使用Xslt指令
:
--
我建议在可能的情况下始终使用AVT——这样可以使代码更短、更简单、更易懂。请不要在一行中发布XML文档。提供的XML(片段,因为没有根)与XSL样式表不匹配(字段
带有一些属性的空元素,但这里肯定没有位置
属性和//数据/行
路径)
您只为每个循环提供了XSL:for的一部分XSL。我猜您正在寻找类似于:
<xsl:for-each select="//Data/Row">
<li>
<a href="{@Location}toheathrow.aspx">
<xsl:value-of select="@Location"/>
</a>
</li>
</xsl:for-each>
编辑:
将
{concat(@Location,'toheathrow.aspx')}
更改为{@Location}toheathrow.aspx
。它更紧凑。问得好,+1。关于三种不同的XSLT1.0解决方案和第四种仅在XSLT2.0中可用的解决方案,请参见我的答案。我建议在可能的情况下始终使用AVT。糟糕的问题-1!您发布的代码不会添加您抱怨的空白。我得到的印象是,你真正的代码不同,在“toHeathrow”字符串旁边有空格,但你让我猜不透。@Michael Kay:我认为@matt在格式化他的代码时有困难。当我读到这个问题时,在“toHeathrow.aspx”后面有一个回车和空格,这可能是我自己的IDE重新格式化的结果。@Dimitre,谢谢你的建议。我希望我修复了代码发布问题。我可以通过在出现空格的地方添加下划线来解决这个问题。但是我现在要尝试AVT的想法,因为我宁愿丢失下划线。@Michael,很抱歉格式化问题。没有可见的空白,但单击链接时,空白就在那里。我加的下划线消除了这个问题。
<a>
<xsl:attribute name="href">
<xsl:value-of select="@Location"/>
<xsl:text>toheathrow.aspx</xsl:text>
</xsl:attribute>
<xsl:value-of select = "@Location" />
</a>
<li>
<a>
<xsl:attribute name="href"
select="concat(@Location, 'toheathrow.aspx')"/>
<xsl:value-of select = "@Location" />
</a>
</li>
<xsl:for-each select="//Data/Row">
<li>
<a href="{@Location}toheathrow.aspx">
<xsl:value-of select="@Location"/>
</a>
</li>
</xsl:for-each>
normalize-space(' some scattered value ') = 'some scattered value'