Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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将atom xml转换为html-如何显示原始html_Html_Xml_Xslt_Atom Feed - Fatal编程技术网

使用xslt将atom xml转换为html-如何显示原始html

使用xslt将atom xml转换为html-如何显示原始html,html,xml,xslt,atom-feed,Html,Xml,Xslt,Atom Feed,我正在将atom xml转换为html,但在xml中有显示html的元素,在结果中我将其作为文本 XML: <feed xmlns="http://www.w3.org/2005/Atom" xmlns:v3="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:base="http://apps.nlm.nih.gov/medlineplus/services/" xml:lang="es"&

我正在将atom xml转换为html,但在xml中有显示html的元素,在结果中我将其作为文本

XML:

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:v3="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:base="http://apps.nlm.nih.gov/medlineplus/services/" xml:lang="es">
<title type="text">MedlinePlus Connect</title>
<subtitle type="text">MedlinePlus Connect results for ICD-9-CM 250.33</subtitle>
<author>
    <name>U.S. National Library of Medicine</name>
    <uri>http://www.nlm.nih.gov</uri>
</author>
<updated type="text">2014-01-29T01:01:09Z</updated>
<category scheme="REDS_MT010001UV" term="MATCHED">
    <v3:mainSearchCriteria xmlns:v3="urn:hl7-org:v3" classCode="OBS" moodCode="DEF">
        <v3:code xmlns:v3="urn:hl7-org:v3" code="KSUBJ" codeSystem="2.16.840.1.113883.5.4"/>
        <v3:value xmlns:v3="urn:hl7-org:v3" code="250.33" codeSystem="2.16.840.1.113883.6.103" displayName="Diabetes mellitus with other coma type 1 uncontrolled"/>
    </v3:mainSearchCriteria>
    <v3:informationRecipient xmlns:v3="urn:hl7-org:v3" typeCode="IRCP">
        <v3:patient xmlns:v3="urn:hl7-org:v3" classCode="PAT"/>
    </v3:informationRecipient>
</category>
<id/>
<entry>
    <title>Coma</title>
    <link href="http://www.nlm.nih.gov/medlineplus/spanish/coma.html" rel="alternate"/>
    <id> tag: nlm.nih.gov, 2014-29-01:/medlineplus/spanish/coma.html </id>
    <updated>2014-01-29T01:01:09Z</updated>
    <summary type="html">
        <p class="NLMalsoCalled">Otros nombres: Estado vegetativo</p> <p>El coma es un estado profundo de inconsciencia. Una persona en coma está viva pero incapaz de moverse o responder a su entorno. El estado de coma se puede presentar como una complicación de una enfermedad subyacente o como resultado de lesiones, tales como <a href="http://www.nlm.nih.gov/medlineplus/spanish/traumaticbraininjury.html">traumatismo del cráneo</a>. </p>
        <p>El estado de coma rara vez dura más de 2 a 4 semanas. El resultado depende de la causa, la severidad y sitio de la lesión. La gente puede salir de un coma con problemas físicos, intelectuales y psicológicos. Algunas personas pueden permanecer en coma durante años o incluso décadas. Para esa gente, la causa de muerte más común es una infección, como una neumonía. </p>
        <p class="NLMattribution">  NIH: Instituto Nacional de Trastornos Neurológicos y Accidentes Cerebrovasculares</p> <p class="NLMrelatedLinks"><ul><li><a href="http://www.nlm.nih.gov/medlineplus/spanish/ency/article/003931.htm">Electroencefalograma</a></li></ul></p>
    </summary>
</entry>
</feed>

MedlinePlus连接
ICD-9-CM的MedlinePlus连接结果250.33
. 

这是一个很好的例子。结果取决于原因、原因和地点。关于昏迷问题,知识和心理咨询。阿尔古纳斯是昏迷中的永久性人物。这是一个新的时代,是一个新的时代

NIH:国家神经系统和脑血管意外研究所

XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:atom="http://www.w3.org/2005/Atom"
version="1.0">
<xsl:output method="html"/>
  <xsl:template match="atom:feed">
    <html>
        <body>
            <atom:Feed>
                  <atom:entries rdf:parseType="Collection">
                    <xsl:for-each select="atom:entry">
                      <atom:Entry>
                            <p>
                            <xsl:for-each select="atom:title">
                                    <xsl:apply-templates select="." mode="object"/>
                            </xsl:for-each>
                            </p>
                            <p>
                            <a href="{atom:link/@href}">For More Data</a> 
                            </p>
                            <p>
                            <xsl:for-each     select="atom:summary">
                                    <xsl:apply-templates select="." mode="html"/>
                            </xsl:for-each>
                            </p>
                  </atom:Entry>
                </xsl:for-each>
               </atom:entries>
        </atom:Feed>
    </body>
</html>
  </xsl:template>
</xsl:stylesheet>

我不想看到里面的HTML 将与设计一起显示,而不是作为文本显示

问题在于:

        <xsl:for-each select="atom:summary">
                                <xsl:apply-templates select="." mode="html"/>
                    </xsl:for-each>

你说问题在于

  <xsl:apply-templates select="." mode="html"/>

的确如此!这里使用的是模式属性,但XSLT中没有指定此模式的模板。当然,您可能会显示XSLT的精简版本,但假设没有,在这种情况下,当XSLT找不到匹配的模板时,将使用其内置模板,这些模板最终将在节点内输出文本

尝试将此模板添加到XSLT

<xsl:template match="*" mode="html">
   <xsl:copy-of select="." />
</xsl:template>
<xsl:for-each     select="atom:summary">
   <xsl:apply-templates select="." mode="html"/>
</xsl:for-each>

但是,您可能会发现,执行此操作时,输出如下所示

<p xmlns="http://www.w3.org/2005/Atom" class="NLMalsoCalled">Otros nombres...

其他名称。。。

这是因为summary节点中的元素是原始提要中“”命名空间的一部分。如果不希望名称空间存在,请尝试使用这两个模板

  <xsl:template match="*" mode="html">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@*|node()" mode="html"/>
    </xsl:element>
  </xsl:template>

  <xsl:template match="@*" mode="html">
     <xsl:copy-of select="." />
  </xsl:template>

请注意,XSLT中的这一行

<xsl:template match="*" mode="html">
   <xsl:copy-of select="." />
</xsl:template>
<xsl:for-each     select="atom:summary">
   <xsl:apply-templates select="." mode="html"/>
</xsl:for-each>

可以用这个来代替

   <xsl:apply-templates select="atom:summary" mode="html"/>