在同一行出現,我有一些XML這看起來是這樣的:節點的所有的孩子都在輸出
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD Journal Publishing DTD v2.3 20070202//EN"
"http://dtd.nlm.nih.gov/publishing/2.3/journalpublishing.dtd"><article>
<front>
<!-- Some metadata -->
</front>
<body>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In vel metus felis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas <italic>habitasse</italic> venenatis.</p>
<!-- More elements -->
</body>
<back>
<ref-list>
<ref id="id-28299"><nlm-citation citation-type="journal">
<person-group person-group-type="author"><name><surname>Bar</surname>
<given-names>F</given-names>
</name>
</person-group>
<article-title>Baz</article-title>
<source>Made up</source>
<year>1970</year>
<volume>27</volume>
<issue>(4)</issue>
<fpage>3</fpage>
<lpage>7</lpage>
<pub-id pub-id-type="doi">http://some.url.org</pub-id>
</nlm-citation>
</ref>
<!-- More ref entries -->
</ref-list>
</back>
</article>
我需要改變它,以便ref
元素(和僅 ref元素,所有其他東西都必須保持原樣)每個都包含在單個行中,元素之間有一個空格。 I.E.
<ref id="id-28299"><nlm-citation citation-type="journal"> <person-group person-group-type="author"><name><surname>Bar</surname> <given-names>F</given-names></name></person-group> <article-title>Baz</article-title> <source>Made up</source> <year>1970</year> <volume>27</volume> <issue>(4)</issue> <fpage>3</fpage> <lpage>7</lpage> <pub-id pub-id-type="doi">http://some.url.org</pub-id></nlm-citation></ref>
我可以展開使用這個樣式表的元素做到這一點:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="ref//*">
<xsl:apply-templates/><xsl:if test="following-sibling::*"><xsl:text> </xsl:text></xsl:if>
</xsl:template>
</xsl:stylesheet>
但我想保持標籤。所以我嘗試了以下內容:
<xsl:template match="ref//*">
<xsl:element name="{local-name()}"><xsl:apply-templates/></xsl:element><xsl:if test="following-sibling::*"><xsl:text> </xsl:text></xsl:if>
</xsl:template>
但是現在每個元素都會出現在不同的行上。我也嘗試過使用<xsl:strip-space>
,但這似乎沒有改變輸出。
爲什麼這很重要?您正在輸出XML。 – 2015-03-31 11:46:22
您是否嘗試將縮進設置爲「no」....' '。您還需要執行'',否則只會複製空白節點。 –
2015-03-31 11:46:53
這很重要,因爲只有空白節點纔會保留,並在導入Adobe InDesign時產生問題。計劃是將這種轉變應用於進口。我嘗試過'indent =「no」',但似乎把* everything *放在一行上,這不是我們想要的。 – jorbas 2015-03-31 13:26:34