Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 仅在特定标记之前修剪行尾的空白_Xml_Xslt_Whitespace_Line Breaks - Fatal编程技术网

Xml 仅在特定标记之前修剪行尾的空白

Xml 仅在特定标记之前修剪行尾的空白,xml,xslt,whitespace,line-breaks,Xml,Xslt,Whitespace,Line Breaks,你能帮帮我吗?!我正在处理以下问题:xml中的行以元素开头。其中一些元素具有属性。我需要将逐行文本转换为浮动文本,并在之前修剪空白,以便编写单词时不带空格。同时,有必要保留文本中显示的所有空白,因为有许多不同的标记一个接一个地出现。如果我使用normalizespace函数,那么标记之间的所有空白都会丢失,我需要编写这样的测试 每种情况下 我怎样才能解决这个问题 我发现了这样一个问题 但我不知道如何在我的案例中使用这样的代码 以下是示例文本: <p> <lb n="3"/>

你能帮帮我吗?!我正在处理以下问题:xml中的行以元素开头。其中一些元素具有属性。我需要将逐行文本转换为浮动文本,并在之前修剪空白,以便编写单词时不带空格。同时,有必要保留文本中显示的所有空白,因为有许多不同的标记一个接一个地出现。如果我使用normalizespace函数,那么标记之间的所有空白都会丢失,我需要编写这样的测试 每种情况下

我怎样才能解决这个问题

我发现了这样一个问题 但我不知道如何在我的案例中使用这样的代码

以下是示例文本:

<p>
<lb n="3"/>Ich ergreife diese Gelegenheit eine Bitte an Sie zu rich 
<lb n="4" break="no"/>ten,<span type="inter" xml:id="GR55024-inter2">&#32;</span> zu <span type="inter" xml:id="GR55024-inter3">die</span> Sie mir<span type="inter" xml:id="GR55024-inter4">&#32;</span> die Aufmunterung durch das güti
<lb n="5" break="no"/>ge Versprechen gaben, <span type="inter" xml:id="GR55024-inter5">im Fall ich Bücher von der Je 
<lb n="6" break="no"/>naischen Bibliothek<ptr type="app" target="#GR55024-seite1-les1"/> nöthig haben sollte,</span> mir dieselben 
<lb n="7"/>gefälligst zu verschaffen. Ich <span type="inter" xml:id="GR55024-inter6">bedarf</span> jetzt zur Recen
<lb n="8" break="no"/>sion <span type="inter" xml:id="GR55024-inter7">des Buches</span> über <span type="inter" xml:id="GR55024-inter8">die</span> Verwandschaft der <span type="inter" xml:id="GR55024-inter9">griechischen 
<lb n="9"/>und deutschen</span> Sprache <span type="inter" xml:id="GR55024-inter10">das <hi rend="unterstrichen">Glossarium von</hi></span> <hi rend="unterstrichen"><persName key="">Hesychius</persName></hi>, 
<lb n="10"/><span type="inter" xml:id="GR55024-inter11">edit. Alberti &#x26; Ruhnkenii, und</span> <title type="werk" key=""><persName key=""><hi rend="unterstrichen">Corinthius</hi></persName></title>
<lb n="11"/>de dialectis, in der holländ. Ausgabe von <hi rend="unterstrichen"><persName key="">Koen</persName></hi>, <hi rend="unterstrichen">8<hi rend="unterstrichen">°</hi></hi> und 
</p> 
非常感谢

我正在使用oxygenxml编辑器及其XSLT调试器和saxon9

Xslt模板不工作

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
version="2.0">

<xsl:output method="xhtml" indent="yes"/>
<xsl:preserve-space elements="text"/>

<xsl:template match="/">
    <html>
        <head>
            <title>
                Title
            </title>
        </head>
        <body>
            <div>
            <xsl:apply-templates select="//div[@ana='ausfertigung']">
            </xsl:apply-templates>
            </div>
        </body>
    </html>
</xsl:template>


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

<xsl:template match="p/text()">
    <xsl:text> </xsl:text>
</xsl:template>

<xsl:variable name="special-handling" select="text()
[following-sibling::*[1][self::lb[@break='no']]]"/>

<xsl:template match="text()[following-sibling::*[1][self::lb[@break='no']]]">
    <xsl:if test="$special-handling/ends-with(text(), '\n')"></xsl:if>
<xsl:value-of select="$special-handling/substring-before(text()[following-sibling::*[1]
[self::lb[@break='no']]],'\n')"></xsl:value-of>
</xsl:template>

</xsl:stylesheet>
工作的初步代码已找到

利用这些模板:

<xsl:template name="selectWithoutBreaks" >
<xsl:variable name="linebreak">
    <xsl:text>
</xsl:text>
</xsl:variable>

<xsl:call-template name="replace-string">
    <xsl:with-param name="text" select="."/>
    <xsl:with-param name="replace" select="$linebreak" />
    <xsl:with-param name="with" select="''"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
    <xsl:when test="contains($text,$replace)">
        <xsl:value-of select="substring-before($text,$replace)"/>
        <xsl:value-of select="$with"/>
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="substring-after($text,$replace)"/>
            <xsl:with-param name="replace" select="$replace"/>
            <xsl:with-param name="with" select="$with"/>
        </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="$text"/>
    </xsl:otherwise>
</xsl:choose>
</xsl:template>

您希望对后跟break=no的“lb”元素的文本节点进行特殊处理。您希望在所有其他文本节点中保留空白。因此:

编写一个标识转换,在内容中保留空白

添加一个模板以匹配文本节点,后跟一个break=no的lb元素。或者,在文本节点的现有模板中,将现有代码包装在xsl:choose元素的xsl:other子句中,在它之前添加xsl:when元素,用于文本节点后面紧跟一个适当的lb元素的情况

我们需要测试选择的文本节点的名称;让我们称之为特殊处理文本节点

如果特殊处理文本节点以换行符结尾,则需要将其剥离。使用ends with测试条件,使用substring执行更改。如果您想在末尾去掉多个换行符,但保留所有其他空格不变,那么您有一个稍微复杂一点的任务


考虑向我们展示您所输入的输入样本所需的输出。并告诉我们是否可以将XSLT2.0与Saxon 9、XmlPrime或Altova.Mr一起使用。斯伯伯格·麦克奎尔,谢谢你的回答!由于我是xslt新手,我并不清楚应该如何引用这些特殊的文本处理节点。是这样吗:?一步一个脚印。你有工作身份转换吗?如果没有,就不要担心特殊处理节点,编写一个。然后添加与特殊处理节点匹配的模板;匹配模式与您拥有的XPath非常相似:match=text[以下同级::*[1][self::tei:lb[@break='no']][.通过使此模板在输出中可见来进行测试。然后担心删除空白。非常感谢您的提示!好吧,当我有这样一个段落模板时,它会在内容中保留空白:

。说到匹配文本节点的模板,它应该是或者别的什么?然后,我制作了一个变量和一个模板,它应该与特殊的处理节点一起工作,我得到了一个荒谬的输出…``我已经在我的主要帖子中添加了xsl。
<xsl:template name="selectWithoutBreaks" >
<xsl:variable name="linebreak">
    <xsl:text>
</xsl:text>
</xsl:variable>

<xsl:call-template name="replace-string">
    <xsl:with-param name="text" select="."/>
    <xsl:with-param name="replace" select="$linebreak" />
    <xsl:with-param name="with" select="''"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
    <xsl:when test="contains($text,$replace)">
        <xsl:value-of select="substring-before($text,$replace)"/>
        <xsl:value-of select="$with"/>
        <xsl:call-template name="replace-string">
            <xsl:with-param name="text" select="substring-after($text,$replace)"/>
            <xsl:with-param name="replace" select="$replace"/>
            <xsl:with-param name="with" select="$with"/>
        </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="$text"/>
    </xsl:otherwise>
</xsl:choose>
</xsl:template>