[英]Convert copied node to string in XSLT 1.0
Using an XSLT file in XSLT 1.0 (and purely 1.0), I am working with XML files, and have used the following code so far to copy a given node from a xml file: Using an XSLT file in XSLT 1.0 (and purely 1.0), I am working with XML files, and have used the following code so far to copy a given node from a xml file:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes" />
<xsl:template match="/">
<xsl:copy-of select="/Heading/subsection/information"/>
</xsl:template>
</xsl:stylesheet>
Now I want to convert this copied node/everything within the node to a string and return it within a parameter, but for the string conversion itself I am unsure of how to proceed with it and present it as I need all the information within the node as a string as opposed to a single line现在我想将此复制的节点/节点内的所有内容转换为字符串并在参数中返回它,但对于字符串转换本身,我不确定如何继续并呈现它,因为我需要节点内的所有信息作为一个字符串而不是单行
The end result would be going from the original node of最终结果将来自原始节点
<information>
<stuff>this is a message</stuff>
<stuff2>another message</stuff2>
</information>
to the string(s):到字符串:
information
stuff this is a message
stuff2 another message
Possibly you want to set the output mode to text:可能您想将 output 模式设置为文本:
<xsl:output mode="text" />
This is optional, but makes sense if you goal is to create a regular text document and don't want the output to be XML-escaped.这是可选的,但如果您的目标是创建常规文本文档并且不希望 output 被 XML 转义,则这是有意义的。
Then add a template for <information>
elements that outputs multiple lines (manually add the newline 

):然后为输出多行的<information>
元素添加一个模板(手动添加换行符

):
<xsl:template match="information">
<xsl:value-of select="concat(name(), '
')" />
<xsl:value-of select="concat(stuff, '
')" />
<xsl:value-of select="concat(stuff2, '
')" />
</xsl:template>
Possible variants would be:可能的变体是:
<xsl:value-of select="concat(name(), '
', stuff, '
', stuff2, '
')" />
or或者
<xsl:value-of select="name()" /><xsl:text>
</xsl:text>
<xsl:value-of select="stuff" /><xsl:text>
</xsl:text>
<xsl:value-of select="stuff2" /><xsl:text>
</xsl:text>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.