I'm converting atom xml to html but in the xml I have element that shows html and in my result I get it as text.

The 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>

The 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>

I wan't that the HTML inside will shown with the design and not as text

The problem is in:

        <xsl:for-each select="atom:summary">
                                <xsl:apply-templates select="." mode="html"/>
                    </xsl:for-each>
有帮助吗?

解决方案

You say the problem is with this...

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

Indeed it is! You are using the mode attribute here, but there is no template present in your XSLT that has this mode specified. Of course, you might be showing a cut-down version of your XSLT, but assuming not, what will happen in this case is that when XSLT cannot find a template that matches, its built-in templates will be used, and these will ultimately output the text within the nodes.

Try adding this template to your XSLT

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

However, you might find when you do this, the output looks like this...

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

This is because the elements within the summary node are part of the "http://www.w3.org/2005/Atom" namespace in the original feed. If you don't want the namespaces present, try these two templates instead

  <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>

Do note that this line in your XSLT

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

Can be replaced with just this

   <xsl:apply-templates select="atom:summary" mode="html"/>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top