1

I try to modified a xml document that has html inside a tag I can transform <p> and list but I have bold and italics inside. How can I make this? I use xslt templates to transform.

This is my code:

<Memoria>     
  <titulo>Memoria EUITI 2010</titulo>
  <Indice>
     <titulo>Indice 2010</titulo>
    <secciones>
      <seccion>
       <parent_id>1</parent_id>
         <titulo>INFORMACI&#211;N GENERAL</titulo>
          <contenido><p><strong>ESTO</strong> ES UNA <em>PRUEBA</em></p></contenido>
<ul>
    <li> caso de poner</li>
</ul>
<p>Ver si funciiona esto que si funciona ya esta</p>
<p> </p></contenido
      </seccion>
    </secciones>
  </Indice>
</Memoria>

I use this xslt transformation:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/"> 

     <Memoria>
       <xsl:apply-templates select="//Memoria"/>
     </Memoria>
  </xsl:template>
  <xsl:template match="text()"/>

  <xsl:template match="titulo">
    <titulo>
      <xsl:value-of select="."/>
    </titulo>
  </xsl:template>

  <xsl:template match="Indice/titulo">
   <Indice>
      <xsl:value-of select="."/>
    </Indice>
  </xsl:template>

  <xsl:template match="Indice/secciones/seccion">
     <Seccion>
      <xsl:apply-templates select="contenido|titulo"/>
   </Seccion>

  </xsl:template>

  <xsl:template match="Indice/secciones/seccion/titulo">
    <nombre_seccion>
      <xsl:value-of select="."/>
    </nombre_seccion>
  </xsl:template>  


  <xsl:template match="contenido">
    <Contenido>
      <xsl:apply-templates select="p|ul"/>
    </Contenido>
  </xsl:template>


  <xsl:template match="p">
    <p>
      <xsl:value-of select="."/>
    </p>
  </xsl:template>

  <xsl:template match="ul">
    <ul>
      <xsl:for-each select="li">
    <li>
      <xsl:value-of select="."/>
    </li>
      </xsl:for-each>
    </ul>
 </xsl:template>
</xsl:stylesheet>

With this template I get a xml valid document but this document doesn't get inside:

  <contenido><p><strong>ESTO</strong> ES UNA <em>PRUEBA</em></p></contenido>

How can I make this?

On the other hand I want to transform this result document with another XSLT in XSL-FO to generate a PDF with FOP. I can generate p and a list but I can't generate bold and cursive.

Is this the correct way to do this:

HTML->XML->XSL-FO

or are there any ways to transform the code directly?

1
  • Indent the code properly .. Use conventional names like root, foo, bar, child. Keep your question simpler and neat .. try to reduce your work XML docs to sample XMLs, so that it would be readable and easily understandable. Questions like this hardly sound interesting .. Commented Mar 1, 2012 at 13:48

1 Answer 1

1

If you want to copy the mixed content of an element, i.e. including all mark-up, then you need to use copy-of instead of value-of. E.g.:

<xsl:template match="p">
  <xsl:copy-of select="."/>
</xsl:template>

This puts in the output the p element itself, all the text content and all the child elements, thereby including , etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.