XSLT for XML到XML的转换

拉加夫

我们有一个XML文档中必须包含多个语言值的要求。其中一些是希伯来语/阿拉伯语。

我正在尝试使用XSLT转换XML,以便可以在显示或使用它的任何内容中更改短语的方向。以下是我们使用的格式的示例。

<booklet>
<page><Short_name> IL</Short_name>
<Phrase>Arabic words 1</Phrase>
<Phrase>Arabic words 2</Phrase>
<Pagebreak> </Pagebreak>
</page><page><Short_name></Short_name>
<Phrase>english words 1</Phrase>
<Phrase>english words 2</Phrase>
<Phrase>english words 3</Phrase>
<Phrase>english words 4</Phrase>
</page></booklet>

下面是我正在寻找的XSLT文件

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <booklet>
      <xsl:for-each select="booklet/page">
        <page>
          <xsl:element name="Short_name">
            <xsl:value-of select="Short_name"/>
          </xsl:element>
          <xsl:for-each select="Phrase">
            <Phrase>
              <xsl:value-of select="@Phrase"/>
            </Phrase>
          </xsl:for-each>
          <xsl:element name="Pagebreak">
            <xsl:value-of select="Pagebreak"/>
          </xsl:element>
        </page>
      </xsl:for-each>
    </booklet>
  </xsl:template>
</xsl:stylesheet>

这不会呈现Phrase标签的值,并且始终显示为空。不知道这是什么错误。

我还需要帮助为其中具有阿拉伯语值的pharse将direction属性设置为RTL,我可以使用短名称值来检测它们,但不确定如何在XSLT中设置direction属性。

预期结果如下所示

<?xml version="1.0" encoding="utf-8"?>
<booklet xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <page>
    <Short_name>IL</Short_name>
    <Phrase>זהו מבחן עברי 1</Phrase>  **---- This phrase needs to be RTL**
    <Phrase>זהו מבחן עברי 2</Phrase>  ---- This phrase needs to be RTL
    <Phrase>זהו מבחן עברי 3</Phrase>  ---- This phrase needs to be RTL
    <Phrase>english wording 2 test</Phrase>  ---- This phrase needs to be LTR
    <Pagebreak> </Pagebreak>
  </page>
  <page>
    <Short_name></Short_name>
    <Phrase>English test 1</Phrase>   ---- This phrase needs to be LTR
    <Phrase>English test 2</Phrase>  ---- This phrase needs to be LTR
  </page>
</booklet>
卢塞罗

我不确定预期的输出是什么(尤其是在RTL方面),但是与的问题Phrase是您要对其进行迭代,然后尝试将其值读取为属性(不是)。

以下更改产生了以下短语:

      <xsl:for-each select="Phrase">
        <Phrase>
          <xsl:value-of select="."/>
        </Phrase>
      </xsl:for-each>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章