XSLT 连接字符串

发布于 2024-10-19 21:36:38 字数 1945 浏览 0 评论 0原文

我有以下

   <R N="14" MIME="application/pdf">
       <RK>7</RK>
       <FS NAME="date" VALUE="2007-11-01" />
       <MT N="Abstract" V="Lorem Ipsum is simply dummy text of the printing " />
       <MT N="Abstract1" V="and typesetting industry. Lorem Ipsum has been the industry's standard " />
       <MT N="Abstract2" V="dummy text ever since the 1500s, when an unknown printer took a galley" />
       <MT N="CreationDate" V="D:20070730173554+05'30'" />
       <MT N="Creator" V="PageMaker 6.5" />
       <MT N="Producer" V="Acrobat Distiller 8.0.0 (Windows)" />
       <MT N="ModDate" V="D:20071024091122+05'30'" />
       <S>
           <b>...</b> handling / storage. Operational reactor physics plays an important role in<br/>
           efficient, smooth and safe operation of <b>nuclear reactor</b>. In <b>...</b>
       </S>
       <LANG>en</LANG>
   </R>

使用 XSLT 的 XML,我需要连接 Abstract、Abstract1、Abstract2、Abstract3... 等的值。

我的 XSLT 是这样的

 <xsl:template match="R">
    <xsl:choose>
        <xsl:when test="MT[@N = 'Abstract' and @V != '']">
            <xsl:call-template name="reformat_keyword">
                <xsl:with-param name="orig_string" select="concat(MT[@N='Abstract']/@V,MT[@N='Abstract1']/@V,MT[@N='Abstract2']/@V)" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:if test="$show_res_snippet != '0'">
                <xsl:call-template name="reformat_keyword">
                    <xsl:with-param name="orig_string" select="S" />
                </xsl:call-template>
            </xsl:if>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

我需要一个通用函数而不是静态连接。

I have the following XML

   <R N="14" MIME="application/pdf">
       <RK>7</RK>
       <FS NAME="date" VALUE="2007-11-01" />
       <MT N="Abstract" V="Lorem Ipsum is simply dummy text of the printing " />
       <MT N="Abstract1" V="and typesetting industry. Lorem Ipsum has been the industry's standard " />
       <MT N="Abstract2" V="dummy text ever since the 1500s, when an unknown printer took a galley" />
       <MT N="CreationDate" V="D:20070730173554+05'30'" />
       <MT N="Creator" V="PageMaker 6.5" />
       <MT N="Producer" V="Acrobat Distiller 8.0.0 (Windows)" />
       <MT N="ModDate" V="D:20071024091122+05'30'" />
       <S>
           <b>...</b> handling / storage. Operational reactor physics plays an important role in<br/>
           efficient, smooth and safe operation of <b>nuclear reactor</b>. In <b>...</b>
       </S>
       <LANG>en</LANG>
   </R>

Using XSLT, I need to concatenate the values of Abstract, Abstract1, Abstract2, Abstract3... so on.

My XSLT is something like this

 <xsl:template match="R">
    <xsl:choose>
        <xsl:when test="MT[@N = 'Abstract' and @V != '']">
            <xsl:call-template name="reformat_keyword">
                <xsl:with-param name="orig_string" select="concat(MT[@N='Abstract']/@V,MT[@N='Abstract1']/@V,MT[@N='Abstract2']/@V)" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:if test="$show_res_snippet != '0'">
                <xsl:call-template name="reformat_keyword">
                    <xsl:with-param name="orig_string" select="S" />
                </xsl:call-template>
            </xsl:if>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

Instead of the static concatenation, I need a generic function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉默的熊 2024-10-26 21:36:38

在 XSLT 2.0 中,它是

<xsl:variable name="answer" 
    select="string-join(MT[starts-with(@N, 'Abstract']/@V, '')"/>

在 XSLT 1.0 中,它是

<xsl:variable name="answer">
  <xsl:for-each select="MT[starts-with(@N, 'Abstract']">
    <xsl:value-of select="@V"/>
  </xsl:for-each>
</xsl:variable>

In XSLT 2.0, it's

<xsl:variable name="answer" 
    select="string-join(MT[starts-with(@N, 'Abstract']/@V, '')"/>

In XSLT 1.0, it's

<xsl:variable name="answer">
  <xsl:for-each select="MT[starts-with(@N, 'Abstract']">
    <xsl:value-of select="@V"/>
  </xsl:for-each>
</xsl:variable>
记忆消瘦 2024-10-26 21:36:38

如果我猜对了,你可以像

<xsl:variable name="con-cats"><xsl:apply-templates
    select="MT[starts-with(@N,'Abstract')]"
    mode="concatthem"/></xsl:variable>

其他地方一样做一些事情:(

<xsl:template match="MT" mode="concatthem">
 <xsl:value-of select="@V"/>
</xsl:template>
<xsl:template match="*|text()" mode="concatthem" />

未经测试,可能有错误)。

If I get you right, you can do something like

<xsl:variable name="con-cats"><xsl:apply-templates
    select="MT[starts-with(@N,'Abstract')]"
    mode="concatthem"/></xsl:variable>

elsewhere:

<xsl:template match="MT" mode="concatthem">
 <xsl:value-of select="@V"/>
</xsl:template>
<xsl:template match="*|text()" mode="concatthem" />

(not tested, may have errors).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文