Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用xslt从xml中剥离标记,同时保留包含的文本和父标记_Xml_Xslt_Strip Tags - Fatal编程技术网

使用xslt从xml中剥离标记,同时保留包含的文本和父标记

使用xslt从xml中剥离标记,同时保留包含的文本和父标记,xml,xslt,strip-tags,Xml,Xslt,Strip Tags,我尝试从一些XML中剥离标记,如下所示: <vocabularyModel> <conceptDomain name="ActAccountType"> <annotations> <documentation> <definition> <text> <p>

我尝试从一些XML中剥离标记,如下所示:

<vocabularyModel>
<conceptDomain name="ActAccountType">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>
                        <b>Description: </b>more txt here </p>
                    <p>
                        <i>Examples: </i>
                    </p>
                    <p/>
                    <ul>
                        <li>
                            <p>Patient billing accounts</p>
                        </li>
                        <li>
                            <p>Cost center</p>
                        </li>
                        <li>
                            <p>Cash</p>
                        </li>
                    </ul>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationInformationCode">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>long text.</p>
                    <p>long text.</p>
                    <p>long text.</p>
                    <p>long text.</p>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationType">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>
                        <b>Description: </b>more text.</p>
                    <p>
                        <i>Examples: </i>
                    </p>
                    <p/>
                    <ul>
                        <li>
                            <p>adjudicated with adjustments</p>
                        </li>
                        <li>
                            <p>adjudicated as refused</p>
                        </li>
                        <li>
                            <p>adjudicated as submitted</p>
                        </li>
                    </ul>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<vocabularyModel>
<conceptDomain name="ActAccountType">
    <annotations>
        <documentation>
            <definition>
                <text>
                   Description: more txt here 
                        Examples: 
                          Patient billing accounts
                          Cost center
                          Cash
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationInformationCode">
    <annotations>
        <documentation>
            <definition>
                <text>
                    long text.
                    long text.
                    long text.
                    long text.
                </text>
            </definition>
        </documentation>
    </annotations>>
</conceptDomain>
<conceptDomain name="ActAdjudicationReason">
    <annotations>
        <documentation>
            <definition>
                <text>
                    long text.
                    long text.
                    long text.
                    long text.
                </text>
            </definition>
        </documentation>
    </annotations>
    <specializesDomain name="ActReason"/>
</conceptDomain>
<conceptDomain name="ActAdjudicationType">
    <annotations>
        <documentation>
            <definition>
                <text>
                        Description: more text.
                        Examples: 
                            adjudicated with adjustments
                            adjudicated as refused
                            adjudicated as submitted
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
    <xsl:output method="xml"  indent="yes"/>


<xsl:template name="strip-tags">
    <xsl:param name="html"/>
    <xsl:choose>
        <xsl:when test="contains($html, '&lt;')">
            <xsl:value-of select="substring-before($html, '&lt;')"/>
            <xsl:call-template name="strip-tags">
                <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$html"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>


<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="definition">
    <xsl:call-template name="strip-tags">
        <xsl:with-param name="html" select="text"/>
    </xsl:call-template>
</xsl:template>


描述:更多信息请点击此处

示例:

  • 病人帐单帐户

  • 成本中心

  • 现金

长文本

长文本

长文本

长文本

描述:更多文本

示例:

  • 经调整裁定

  • 裁定被拒绝

  • 裁定为提交

其中,文本下面的所有子标记都将被剥离,但所需的xml和文本如下所示:

<vocabularyModel>
<conceptDomain name="ActAccountType">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>
                        <b>Description: </b>more txt here </p>
                    <p>
                        <i>Examples: </i>
                    </p>
                    <p/>
                    <ul>
                        <li>
                            <p>Patient billing accounts</p>
                        </li>
                        <li>
                            <p>Cost center</p>
                        </li>
                        <li>
                            <p>Cash</p>
                        </li>
                    </ul>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationInformationCode">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>long text.</p>
                    <p>long text.</p>
                    <p>long text.</p>
                    <p>long text.</p>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationType">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>
                        <b>Description: </b>more text.</p>
                    <p>
                        <i>Examples: </i>
                    </p>
                    <p/>
                    <ul>
                        <li>
                            <p>adjudicated with adjustments</p>
                        </li>
                        <li>
                            <p>adjudicated as refused</p>
                        </li>
                        <li>
                            <p>adjudicated as submitted</p>
                        </li>
                    </ul>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<vocabularyModel>
<conceptDomain name="ActAccountType">
    <annotations>
        <documentation>
            <definition>
                <text>
                   Description: more txt here 
                        Examples: 
                          Patient billing accounts
                          Cost center
                          Cash
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationInformationCode">
    <annotations>
        <documentation>
            <definition>
                <text>
                    long text.
                    long text.
                    long text.
                    long text.
                </text>
            </definition>
        </documentation>
    </annotations>>
</conceptDomain>
<conceptDomain name="ActAdjudicationReason">
    <annotations>
        <documentation>
            <definition>
                <text>
                    long text.
                    long text.
                    long text.
                    long text.
                </text>
            </definition>
        </documentation>
    </annotations>
    <specializesDomain name="ActReason"/>
</conceptDomain>
<conceptDomain name="ActAdjudicationType">
    <annotations>
        <documentation>
            <definition>
                <text>
                        Description: more text.
                        Examples: 
                            adjudicated with adjustments
                            adjudicated as refused
                            adjudicated as submitted
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
    <xsl:output method="xml"  indent="yes"/>


<xsl:template name="strip-tags">
    <xsl:param name="html"/>
    <xsl:choose>
        <xsl:when test="contains($html, '&lt;')">
            <xsl:value-of select="substring-before($html, '&lt;')"/>
            <xsl:call-template name="strip-tags">
                <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$html"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>


<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="definition">
    <xsl:call-template name="strip-tags">
        <xsl:with-param name="html" select="text"/>
    </xsl:call-template>
</xsl:template>

描述:更多信息请点击此处
示例:
病人帐单帐户
成本中心
现金
长文本。
长文本。
长文本。
长文本。
>
长文本。
长文本。
长文本。
长文本。
描述:更多文本。
示例:
经调整裁定
裁定被拒绝
裁定为提交

我已尝试在此处其他地方找到并修改了以下内容:

<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="p | b | li | ul | i">
    <xsl:apply-templates/>
</xsl:template>

但这并没有去除任何元素,即使我将匹配限制为仅在元素上。我还尝试了以下几种变体:

<vocabularyModel>
<conceptDomain name="ActAccountType">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>
                        <b>Description: </b>more txt here </p>
                    <p>
                        <i>Examples: </i>
                    </p>
                    <p/>
                    <ul>
                        <li>
                            <p>Patient billing accounts</p>
                        </li>
                        <li>
                            <p>Cost center</p>
                        </li>
                        <li>
                            <p>Cash</p>
                        </li>
                    </ul>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationInformationCode">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>long text.</p>
                    <p>long text.</p>
                    <p>long text.</p>
                    <p>long text.</p>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationType">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>
                        <b>Description: </b>more text.</p>
                    <p>
                        <i>Examples: </i>
                    </p>
                    <p/>
                    <ul>
                        <li>
                            <p>adjudicated with adjustments</p>
                        </li>
                        <li>
                            <p>adjudicated as refused</p>
                        </li>
                        <li>
                            <p>adjudicated as submitted</p>
                        </li>
                    </ul>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<vocabularyModel>
<conceptDomain name="ActAccountType">
    <annotations>
        <documentation>
            <definition>
                <text>
                   Description: more txt here 
                        Examples: 
                          Patient billing accounts
                          Cost center
                          Cash
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationInformationCode">
    <annotations>
        <documentation>
            <definition>
                <text>
                    long text.
                    long text.
                    long text.
                    long text.
                </text>
            </definition>
        </documentation>
    </annotations>>
</conceptDomain>
<conceptDomain name="ActAdjudicationReason">
    <annotations>
        <documentation>
            <definition>
                <text>
                    long text.
                    long text.
                    long text.
                    long text.
                </text>
            </definition>
        </documentation>
    </annotations>
    <specializesDomain name="ActReason"/>
</conceptDomain>
<conceptDomain name="ActAdjudicationType">
    <annotations>
        <documentation>
            <definition>
                <text>
                        Description: more text.
                        Examples: 
                            adjudicated with adjustments
                            adjudicated as refused
                            adjudicated as submitted
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
    <xsl:output method="xml"  indent="yes"/>


<xsl:template name="strip-tags">
    <xsl:param name="html"/>
    <xsl:choose>
        <xsl:when test="contains($html, '&lt;')">
            <xsl:value-of select="substring-before($html, '&lt;')"/>
            <xsl:call-template name="strip-tags">
                <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$html"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>


<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="definition">
    <xsl:call-template name="strip-tags">
        <xsl:with-param name="html" select="text"/>
    </xsl:call-template>
</xsl:template>


如果我省略了标识转换,它将剥离所有标记,但其他方面只复制原始XML的内容。任何帮助都将不胜感激-scott

显示的第一个样式表的输出(如果添加缺少的
xsl:stylesheet
元素

<vocabularyModel>
   <conceptDomain name="ActAccountType">
      <annotations>
         <documentation>
            <definition>
               <text>Description: more txt here Examples: Patient billing accountsCost centerCash</text>
            </definition>
         </documentation>
      </annotations>
   </conceptDomain>
   <conceptDomain name="ActAdjudicationInformationCode">
      <annotations>
         <documentation>
            <definition>
               <text>long text.long text.long text.long text.</text>
            </definition>
         </documentation>
      </annotations>
   </conceptDomain>
   <conceptDomain name="ActAdjudicationType">
      <annotations>
         <documentation>
            <definition>
               <text>Description: more text.Examples: adjudicated with adjustmentsadjudicated as refusedadjudicated as submitted</text>
            </definition>
         </documentation>
      </annotations>
   </conceptDomain>
</vocabularyModel>

描述:此处有更多示例:患者账单账户成本中心现金
长文本。长文本。长文本。长文本。
描述:更多文本。示例:经调整裁定裁定为驳回裁定为提交裁定

这似乎是您想要的。也许您真正的输入是在名称空间中?

令人困惑。实际根包含一些属性,并且与前面的conceptDomain有几个兄弟,但其他方面如图所示。一旦我去掉xmlns名称,它就可以正常工作。我还不知道如何在xslt中实现这一点,但我会四处看看r一个解决方案。感谢您的关注。@hsb在您的样式表中用前缀(比如说
x
)声明名称空间,然后将
h=“p | b | li | ul | i”
更改为
h=“x:p | x:b | x:li | x:ul x:i”
因此它匹配名称空间中的元素,而不是no-namespace。在这里显示我的无知。也许我不想剥离名称空间,只是以某种方式解释这里声明的默认名称。xmlns=“urn:hl7 org:v3/mif2”某种方式。谢谢,我看到您期待我的响应。再次感谢您的关注。