如何去除逗号和一些内联元素?

时间:2018-12-24 11:31:16

标签: xslt-3.0

我正在从索引字词中删除页码-仅显示不带页码的字词。

我正在努力寻找通配符模式,以查找逗号,后跟链接标记。

这是输入XML:

    <book>
    <index xml:id="index01"><title>Index</title>
    <indexdiv><title>A</title>
    <indexentry xml:id="ie001"><primaryie>abdomen, of neonates, <link role="page" linkend="pg68">68</link></primaryie></indexentry>
    <indexentry xml:id="ie002"><primaryie>abnormal amniotic fluid volume, <link role="page" linkend="pg56">56</link>, <link role="page" linkend="pg56">56</link><emphasis role="italic">t</emphasis></primaryie></indexentry>
    <indexentry xml:id="ie003"><primaryie>abruption placentae. <emphasis role="italic">See</emphasis> placental abruption</primaryie></indexentry>
    <indexentry xml:id="ie004"><primaryie>acceptable and repeatable, <link role="page" linkend="pg343">343</link>&#x2013;<link role="page" linkend="pg344">344</link>, <link role="page" linkend="pg343">343</link><emphasis role="italic">t</emphasis></primaryie>
    <secondaryie>pulmonary function testing, <link role="page" linkend="pg202">202</link>, <link role="page" linkend="pg340">340</link></secondaryie></indexentry>
    <indexentry xml:id="ie005"><primaryie>acinus, <link role="page" linkend="pg31">31</link></primaryie></indexentry>
    </indexdiv>
    </index>
    </book>

我的代码:

    <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" expand-text="yes">

      <xsl:mode streamable="yes" use-accumulators="#all" on-no-match="shallow-copy"/>

      <xsl:output method="xml" encoding="utf-8" indent="yes"/>
      <xsl:variable name="document-uri" select="document-uri(.)"/>
      <xsl:variable name="isbn" select="substring-before((tokenize($document-uri,'/'))[last()],'.')"/>

    <xsl:template match="book">
    <book>
      <xsl:apply-templates select="index"/>
    </book>
    </xsl:template>

    <xsl:template match="index">
        <xsl:apply-templates select="indexdiv/indexentry"/>
    </xsl:template>

    <xsl:template match="indexentry">
      <xsl:apply-templates select="primaryie"/>
      <xsl:apply-templates select="secondaryie"/>
      <xsl:apply-templates select="tertiaryie"/>
    </xsl:template>

    <xsl:template match="primaryie">
        <col1><xsl:value-of select="text()"/></col1>
    </xsl:template>

    <xsl:template match="secondaryie">
      <col2><xsl:value-of select="text()"/></col2>
    </xsl:template>

    <xsl:template match="tertiaryie">
      <col3><xsl:value-of select="."/></col3>
    </xsl:template>

    <xsl:template match="link[@role='page']"/>
    <xsl:template match="emphasis[@role]"/>

    </xsl:stylesheet>

我希望获得以下输出,但是我正在努力使用模式匹配:

    <?xml version="1.0" encoding="utf-8"?>
    <book>
       <col1>abdomen, of neonates</col1>
       <col1>abnormal amniotic fluid volume</col1>
       <col1>abruption placentae.  placental abruption</col1>
       <col1>acceptable and repeatable</col1>
       <col2>pulmonary function testing</col2>
       <col1>acinus</col1>
    </book>

0 个答案:

没有答案