2013-10-04 2 views
0

У меня есть данные, поступающие как этотсохранить пространство приходит в данных в XSLT

<Table1> 
<row_description>Low Touch</row_description> 
<_x0038_ /> 
<_x0039_ /> 
<_x0031_0 /> 
<_x0031_1 /> 
<_x0031_2 /> 
</Table1> 
<Table1> 
<row_description> DMA/ALGO</row_description> 
<_x0038_ /> 
<_x0039_ /> 
<_x0031_0 /> 
<_x0031_1 /> 
<_x0031_2 /> 
</Table1> 
<Table1> 
<row_description> PT</row_description> 
<_x0038_ /> 
<_x0039_ /> 
<_x0031_0 /> 
<_x0031_1 /> 
<_x0031_2 /> 
</Table1> 

и мой XSLT делает это

<xsl:for-each select="*"> 
    <TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
     <xsl:if test="position()=1"> 
      <Paragraph> 
       <Span> 
        <Run> 
         <xsl:value-of select="text()" /> 
        </Run> 
       </Span> 
      </Paragraph> 
     </xsl:if> 
     <xsl:if test="position()>1"> 
      <Paragraph TextAlignment="Right"> 
       <Span> 
        <Run> 
         <xsl:value-of select="text()"/> 
        </Run> 
       </Span> 
      </Paragraph> 
     </xsl:if> 
    </TableCell> 
</xsl:for-each> 

но удаление пространства приходя до моего текста PTPT к. Как сохранить пространство в данных?

ответ

1

Я О.П., и я сделал это, чтобы преодолеть мою проблему

<Run xml:space="preserve"><xsl:value-of select="text()" /></Run> 

Примечание: После написания xml:space="preserve", пожалуйста, убедитесь, что <xsl:value-of select="text()" /> находится в той же строке. Если мы пишем, как этот

<Run xml:space="preserve"> 
    <xsl:value-of select="text()" /> 
</Run> 

будет также рассматривать отступ XSL как текст, как мы уже говорили, чтобы сохранить пространство.

2

В вашем XSLT использовать:

<xsl:preserve-space elements="*" /> 

См: http://www.w3schools.com/xsl/el_preserve-space.asp


Когда у меня есть следующий входной XML:

<?xml version="1.0" encoding="UTF-8"?> 
<data> 
    <Table1> 
     <row_description>Low Touch</row_description> 
     <_x0038_/> 
     <_x0039_/> 
     <_x0031_0/> 
     <_x0031_1/> 
     <_x0031_2/> 
    </Table1> 
    <Table1> 
     <row_description> DMA/ALGO</row_description> 
     <_x0038_/> 
     <_x0039_/> 
     <_x0031_0/> 
     <_x0031_1/> 
     <_x0031_2/> 
    </Table1> 
    <Table1> 
     <row_description> PT</row_description> 
     <_x0038_/> 
     <_x0039_/> 
     <_x0031_0/> 
     <_x0031_1/> 
     <_x0031_2/> 
    </Table1> 
</data> 

И я использую следующий XSLT:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="html" encoding="UTF-8" indent="yes"/> 
    <xsl:preserve-space elements="*" /> 

    <xsl:template match="@*|node()"> 
     <xsl:apply-templates select="@*|node()" /> 
    </xsl:template> 

    <xsl:template match="Table1"> 
     <xsl:for-each select="*"> 
      <TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
       <xsl:if test="position()=1"> 
        <Paragraph> 
         <Span> 
          <Run> 
           <xsl:value-of select="text()" /> 
          </Run> 
         </Span> 
        </Paragraph> 
       </xsl:if> 
       <xsl:if test="position()>1"> 
        <Paragraph TextAlignment="Right"> 
         <Span> 
          <Run> 
           <xsl:value-of select="text()"/> 
          </Run> 
         </Span> 
        </Paragraph> 
       </xsl:if> 
      </TableCell> 
     </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 

Выходные данные показывают, как ожидалось:

<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph><Span><Run>Low Touch</Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph><Span><Run> DMA/ALGO</Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph><Span><Run> PT</Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 
<TableCell Padding="10,1" BorderThickness="1,1,1,1" BorderBrush="#FF888888"> 
    <Paragraph TextAlignment="Right"><Span><Run></Run> 
     </Span></Paragraph> 
</TableCell> 

Значение <Run> PT</Run> еще имеет пробелы в нем. В качестве XSLT-процессора я использовал Altova XMLSpy.

+0

Сделал это. проблема такая же. Я добавил его здесь \t ' –

+0

@NikhilAgrawal, что странно. Я обновил свой ответ на примере XSLT. И пример ввода и вывода. Как вы можете видеть, пробелы сохраняются. Может быть, проблема кроется в вашем процессоре XSLT? –

+0

См. Мой ответ. Спасибо за вашу помощь. +1 от меня. –

Смежные вопросы