简体   繁体   English

XSLT尝试添加新节点并添加元素

[英]XSLT trying to add new node and adding element

Currently I am trying to convert an word xml to xml file. 当前,我正在尝试将单词xml转换为xml文件。 And it is trying to do that by identifying styles. 它正在尝试通过识别样式来做到这一点。

I am currently facing problem here as I am very new to this XLST conversions I am seeking some help. 我目前在这里遇到问题,因为我对XLST转换很陌生,我正在寻求帮助。

I am trying to add a new element called <standingOrder> in below template an from my word xm looks like 我试图在下面的模板中添加一个名为<standingOrder>的新元素,我的单词xm看起来像

Word document Text Word文件文字

  1. PLANNING REGULATIONS (REMOVAL OF PROVISIONS IN RESPECT OF GYPSIES AND TRAVELLERS) Up to 20 minutes (Standing Order No. 23) Mr abc That leave be given to bring in a xxxxxxxxxxxx. 规划规程(取消有关吉普赛人和旅行者的规定) 最多20分钟(第23号临时命令) abc先生请假,以便带上xxxxxxxxxxxx。 Notes: The Member moving and a Member opposing this Motion may each speak for up to 10 minutes. 注意:动议的成员和反对该动议的成员各自最多可以发言10分钟。

Note: 注意:

In above text, Up to 20 minutes (Standing Order No.23) (which is highlighted) will have a style called StandingOrderReference and as below xslt code if that finds the text Standing Order No.23 then it should build a child node called <standingOrder> and value 23 should be the innertext of the node. 在上面的文本中,最多20分钟(23号站立订单)(突出显示)将具有一种名为StandingOrderReference的样式,如下面的xslt代码所示,如​​果找到文本23号站立订单,则应建立一个名为<standingOrder>和值23应该是节点的innertext for that I have done below but I am not able to show the value. 为此,我已经在下面完成了操作,但无法显示其价值。

XSLT XSLT

<xsl:when test="@styleId='StandingOrderReference'">
   <xsl:element name="standingOrder">
      <xsl:value-of select="substring-after(.,'(Standing Order  ')"/>
   </xsl:element>
</xsl:when>

I am expecting 我期待

<standingOrder>23</standingOrder>

Please correct me where I am doing wrong. 请纠正我在哪里做错了。 As always any help is much appreciated. 与往常一样,我们非常感谢您的帮助。

As per the comment, it would be preferable if you placed the actual xml excerpt in the post. 根据评论,如果您在帖子中放置了实际的xml摘录,那将是更好的选择。 However, making some assumptions, the following xslt: 但是,作一些假设,下面的xslt:

   <xsl:template match="/xml/someElement">
      <xsl:choose>
         <xsl:when test="@styleId='StandingOrderReference'">
            <xsl:element name="standingOrder">
               <xsl:value-of select="
                 substring-before(
                   substring-after(.,'(Standing Order No. '), 
                   ')')"/>
            </xsl:element>
         </xsl:when>
      </xsl:choose>
   </xsl:template>

Parses this document: 解析此文档:

<xml>
   <someElement styleId="StandingOrderReference">
      **Up to 20 minutes (Standing Order No. 23)** Mr a
   </someElement>
</xml>

To return what you seem to be after, viz: 要返回您似乎想要的东西,即:

<standingOrder>23</standingOrder>

Note that you'll also need to truncate the substring - I've used a substring-before to do this. 请注意,您还需要截断子substring-beforesubstring-before ,我已经使用了substring-before Note that there is also the word No. after the (Standing Order in the xml. 请注意,在xml中的(Standing Order后面还有单词No. .。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM