如何在xslt中拆分元素值并为这些值分配新元素标记名称



我的输入xml:

<body xmlns:ce="test.com" xmlns:mml="any.com">
<ce:para>         
    The existence of a globally hyperbolic Lorentzian metric on a 
    <mml:math>(3 + 1)</mml:math>
    -spacetime with closed Cauchy surface excludes all but one differentiable structure on the underlying manifold, as observed by ChernovNemirovski 
    <citegroup>
        [
        <cite>
            <no>
                CN13
            </no>
            <id>
                CN
            </id>
        </cite>
        ]
    </citegroup>
    We point out in this note that the diffeomorphism type of a globally hyperbolic 
    <mml:math>(n+ 1)</mml:math>
    -spacetime is determined by the h-cobordism class of its closed Cauchy surface. The precise statement is as follows. 
</ce:para>

我的xslt是;

<body>       
      <xsl:apply-templates select="body/ce:para"/>    
</body>
<xsl:template match="body/ce:para">    
     <xsl:value-of select="ce:para/text[1]"/>    
     <mml:mo stretchy="false">(</mml:mo>    
      <mml:mn>    
     <xsl:value-of select="translate(substring-after(substring-before(mml:math,'+'),'('),' ','')"/>    
    </mml:mn>    
    <mml:mo>    
    <xsl:text>+</xsl:text>    
    </mml:mo>    
    <mml:mn>    
    <xsl:value-of select="translate(substring-before(substring-after(mml:math,'+'),')'),' 
','')"/>    
    </mml:mn>    
    <mml:mo stretchy="false">)</mml:mo>    
   <xsl:value-of select="ce:para/text[2]"/>    
    <mml:mo stretchy="false">(</mml:mo>    
   <mml:mi>    
   <xsl:value-of select="translate(substring-after(substring-before(mml:math,'+'),'('),' ','')"/>    
   </mml:mi>    
   <mml:mo>    
   <xsl:text>+</xsl:text>    
   </mml:mo>    
   <mml:mn>    
   <xsl:value-of select="translate(substring-before(substring-after(mml:math,'+'),')'),' ','')"/>    
   </mml:mn>    
   <mml:mo stretchy="false">)</mml:mo>    
  <xsl:value-of select="ce:para/text[3]"/>    
</xsl:template>

我的预期输出xml:

<body>     
 <ce:para id="p0005">    
   The existence of a globally hyperbolic Lorentzian metric on a 
   <mml:mo stretchy="false">(</mml:mo>    
  <mml:mn>3</mml:mn>    
   <mml:mo>+</mml:mo>    
  <mml:mn>1</mml:mn>    
   <mml:mo stretchy="false">)</mml:mo>    
    </mml:math>    
    -spacetime with closed Cauchy surface excludes all but one differentiable structure on the underlying manifold, as observed by Chernov–Nemirovski 
   <ce:cross-ref>[CN13]</ce:cross-ref>. 
We point out in this note that the diffeomorphism type of a globally hyperbolic 
   <mml:mo stretchy="false">(</mml:mo>    
   <mml:mi>n</mml:mi>    
   <mml:mo>+</mml:mo>    
   <mml:mn>1</mml:mn>    
   <mml:mo stretchy="false">)</mml:mo>    
   </mml:math>    
  -spacetime is determined by the <ce:italic>h</ce:italic>-cobordism class of its closed Cauchy surface. The precise statement is as follows.
 </ce:para>    
</body>

刚刚更正了XSLT。您没有指定要使用哪个子元素mml:math-使用[1]等

这是我的XSLT代码,非常简化了您的任务。到目前为止,您还没有映射到citegroup,但现在您将管理它:

<xsl:template match="body/ce:para">
    <xsl:value-of select="text()[1]"/>
    <xsl:apply-templates select="mml:math[1]"/>
    <xsl:value-of select="text()[2]"/>
    <xsl:apply-templates select="mml:math[2]"/>
    <xsl:value-of select="text()[3]"/>
</xsl:template>
<xsl:template match="mml:math">
    <mml:mo stretchy="false">(</mml:mo>
    <mml:mn>
        <xsl:value-of select="translate(substring-after(substring-before(text(),'+'),'('),' ','')"/>
    </mml:mn>
    <mml:mo>
        <xsl:text>+</xsl:text>
    </mml:mo>
    <mml:mn>
        <xsl:value-of select="translate(substring-before(substring-after(text(),'+'),')'),' 
            ','')"/>
    </mml:mn>
    <mml:mo stretchy="false">)</mml:mo>
</xsl:template>

这创建了以下输出:

<body>         
    The existence of a globally hyperbolic Lorentzian metric on a 
    <mml:mo stretchy="false">(</mml:mo>
    <mml:mn>3</mml:mn>
    <mml:mo>+</mml:mo>
    <mml:mn>1</mml:mn>
    <mml:mo stretchy="false">)</mml:mo>
    -spacetime with closed Cauchy surface excludes all but one differentiable structure on the underlying manifold, as observed by ChernovNemirovski 
    <mml:mo stretchy="false">(</mml:mo>
    <mml:mn>n</mml:mn>
    <mml:mo>+</mml:mo>
    <mml:mn>1</mml:mn>
    <mml:mo stretchy="false">)</mml:mo>
    We point out in this note that the diffeomorphism type of a globally hyperbolic 
</body>

最新更新