【问题标题】:adding a Carriage Return in XSLT using wordml使用 wordml 在 XSLT 中添加回车
【发布时间】:2018-11-03 22:10:33
【问题描述】:

我正在使用 XSLT (1.0) 使用 WordML 生成 Word 文档。我有不同的表,并且在其中一列中我需要添加由回车分隔的值。

即:而不是Lot1Lot2Lot3,我需要:

Lot1
Lot2
Lot3

我已经搜索了所有相关主题,但找不到任何可以解决我的问题的解决方案。我曾尝试在<xsl:text> 中使用<w:br/><xsl:text></xsl:text> 或dec 代码 / ,但没有奏效,因为我仍然在同一行中看到结果。

XML:

<Root>
 <elemName>Test</elemName>
 <elemDescription>Description</elemDescription>
 <Items>
  <Item1Flag>Y</Item1Flag>
  <Item1Value>123213123</Item1Flag>
 </Items> 
 <Items>
  <Item1Flag>Y</Item1Flag>
  <Item1Value>12223123</Item1Flag>
 </Items>
 <Items>
  <Item1Flag>Y</Item1Flag>
  <Item1Value>1232423</Item1Flag>
 </Items>
</Root>

样式表:

...
<w:t><xsl:call-template name="concatItems">
<xsl:with-param name="elements" select="Items[Item1Flag='Y']/Item1Value"/>
</xsl:call-template>
</w:t>
...

<!-- Template -->
<xsl:template name="concatItems">
  <xsl:param name="elements"/>
  <xsl:variable name="result">
    <xsl:for-each select="$elements">
      <xsl:value-of select="."/>
      <xsl:if test="position()!=last()"><w:br/></xsl:if>
    </xsl:for-each>
  </xsl:variable>
  <xsl:value-of select="$result"/>  
</xsl:template>

【问题讨论】:

  • XPath Items[Item1Flag='Y']/Item3 查找 Items 标记的 Item3 子标记,该标记包含具有文本值 YItem1Flag。我在您的任何 Items 元素中都看不到任何 Item3 元素。请edit您的帖子并提供一致的输入和输出。
  • 谢谢。经过数小时的测试和研究,我想我已经设法解决了它。我删除了模板用法,只使用代码

标签: xml xslt-1.0 wordml


【解决方案1】:

我没有使用模板,而是直接在样式表中调用 for-each 并使用&lt;w:br/&gt;

<w:t><xsl:for-each select="Items[Item1Flag='Y']/Item1Value"><xsl:value-of select="."/><xsl:if test="position()!=last()"><w:br/></xsl:if></xsl:for-each></w:t> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-07
    • 2017-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 1970-01-01
    相关资源
    最近更新 更多