2013-05-07 54 views
-1

我在下面提到了我的xml文件,xml包含许多内部样式标记(请使用通用的xslt代码来提取所有文本),但它应该提取所有文本在启动innertag之前进行了内部和文本之后。如何从xml中使用xslt提取父标记的父标记文本和扩展文本

<?xml version="1.0" encoding="UTF-8"?> 
<Values> 
    <Value AttributeID="11218"> 
     <Text>WGP03068-CNZH-00 
       <style name="bold">Introduction of the Title</style>xslt 
       <style name="TextStyle1"> 
        The smallest font size for which kerning should be automatically adjusted. 
       </style> 
       <style name="bold">Reference for this book 
        <style name="TextStyle1"> 
        The smallest font size for which kerning should be automatically adjusted. 
       </style> 
       Hope you had a good learning experience. 
       </style> 
       I am expecting more solution for my doughts. 
      </Text> 
     </Value> 
    </Values> 

我的XSLT代码如下提到:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
     <HTML> 
      <xsl:apply-templates /> 
     </HTML> 
    </xsl:template> 

    <xsl:template match="Values"> 
     <xsl:for-each select="Value"> 
      <xsl:for-each select="Text"> 
       <p> 
       <xsl:for-each select="style"> 
        <xsl:value-of select="." /> 
       </xsl:for-each> 
       </p> 
      </xsl:for-each> 
     </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 

我的XSLT缺少启动文本和结束元素的文字它只读取元素,我想全部外线和innertag文本阅读,并添加自己的样式(如粗体,斜体,字体名称和颜色)

我期待输出象下面这样:

WGP03068-CNZH-00 标题介绍 xslt 应该自动调整字距的最小字体大小。 此书的参考资料 字距应该自动调整的最小字体大小,希望你有一个很好的学习经验。 我期待为我的面团提供更多解决方案。

回答

0

更好的方法是使用“推送”方法,并将XSLT样式表编码为一系列匹配模板,并在其中输出所需的html。

例如,要将XML中的文本元素转换为段落,可以使用以下模板。

<xsl:template match="Text"> 
    <p> 
     <xsl:apply-templates /> 
    </p> 
    </xsl:template> 

并输出风格元素大胆,你会有这样的一个模板:

<xsl:template match="style[@name='bold']"> 
    <span style="font-weight:bold"> 
     <xsl:apply-templates /> 
     </span> 
    </xsl:template> 

试试下面的XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:strip-space elements="*" /> 

    <xsl:template match="/"> 
    <HTML> 
     <xsl:apply-templates /> 
    </HTML> 
    </xsl:template> 

    <xsl:template match="Text"> 
    <p> 
     <xsl:apply-templates /> 
    </p> 
    </xsl:template> 

    <xsl:template match="style[@name='bold']"> 
    <span style="font-weight:bold"> 
     <xsl:apply-templates /> 
     </span> 
    </xsl:template> 

    <xsl:template match="style"> 
    <span> 
     <xsl:apply-templates /> 
    </span> 
    </xsl:template> 
</xsl:stylesheet> 

当适用于您的XML,以下是输出

<HTML> 
    <p>WGP03068-CNZH-00 
     <span style="font-weight:bold">Introduction of the Title</span>xslt 
     <span> 
     The smallest font size for which kerning should be automatically adjusted. 
     </span><span style="font-weight:bold">Reference for this book 
     <span> 
      The smallest font size for which kerning should be automatically adjusted. 
      </span> 
     Hope you had a good learning experience. 
     </span> 
     I am expecting more solution for my doughts. 

    </p> 
</HTML> 

请注意,此XSLT使用XSLT的内置模板来输出文本。在<xsl:apply-templates />和XSLT找到文本节点的位置,如果没有匹配的模板,它会自动为您输出文本。

+0

这里我使用ProcessingWordML将XML转换为Word文档 – user2357252 2013-05-07 14:27:45

+0

如果XML具有 20不同的attributeID,如何设置Order格式。我必须检查,如果具有AttributeID =“11111”它应该先显示然后第二应该是AttributeID =“11218”等等..我需要检查attributeID,然后放置位置。请任何人提供解决方案。 – user2357252 2013-05-16 11:54:59

+0

如果您为此提出了一个全新的问题,而不是在评论中提问,那最好。我相信虽然解决这个问题并不难。 – 2013-05-16 12:26:11

相关问题