Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 819707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:21:19+00:00 2026-05-15T02:21:19+00:00

I am new to this, so please bear with me… If we have the

  • 0

I am new to this, so please bear with me…

If we have the following xml fragment:

<docXML>
<PARRAFO orden='1' tipo='parrafo'>
    <dato>
      <etiqueta>Título</etiqueta>
      <tipo>TextBox</tipo>
      <valor>¿Cuándo solicitar el consejo genético?</valor>
      <longitud>1500</longitud>
      <comentario></comentario>
      <enlace></enlace>
      <target_enlace>I</target_enlace>
    </dato>
    <dato>
      <etiqueta>Texto</etiqueta>
      <tipo>Resumen</tipo>
      <valor>Resumen text</valor>
      <longitud>8000</longitud>
      <comentario></comentario>
      <enlace></enlace>
      <target_enlace></target_enlace>
    </dato>
    <dato>
      <etiqueta>Imagen</etiqueta>
      <tipo>TextBox</tipo>
      <valor>http://url/Imagenes/7D2BE6480CF4486CA288A75932606181.jpg</valor>
      <longitud>1500</longitud>
      <comentario></comentario>
      <enlace></enlace>
      <target_enlace>I</target_enlace>
    </dato>
  </PARRAFO>
  <PARRAFO orden='1' tipo='parrafo'>
    <dato>
      <etiqueta>Título</etiqueta>
      <tipo>TextBox</tipo>
      <valor>TextBox text</valor>
      <longitud>1500</longitud>
      <comentario></comentario>
      <enlace></enlace>
      <target_enlace>I</target_enlace>
    </dato>
    <dato>
      <etiqueta>Texto</etiqueta>
      <tipo>Resumen</tipo>
      <valor>Resumen text</valor>
      <longitud>8000</longitud>
      <comentario></comentario>
      <enlace></enlace>
      <target_enlace></target_enlace>
    </dato>
  </PARRAFO>
</docXML>

.. I am going to apply templates to each section depending on the value of the label “etiqueta” per node “dato” in “PARRAFO” by using the following XSLT:

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

  <xsl:output method="html" encoding="iso-8859-1"/>

<xsl:template match="/">
    <xsl:variable name="xml-doc-parrafo" select="documentoXML/PARRAFO"/>
   <!-- PARRAFOS -->
    <xsl:choose>
      <xsl:when test="count($xml-doc-parrafo)>0">
        <div class="seccion_1">
          <xsl:for-each select="$xml-doc-parrafo">
            <xsl:choose>
              <xsl:when test="self::node()[@tipo = 'parrafo']">
                <div class="parrafo">
                  <xsl:for-each select="self::node()[@tipo = 'parrafo']/dato">
                    <xsl:variable name="dato" select="self::node()[@tipo = 'parrafo']/dato"/>
                    <xsl:variable name="nextdato" select="following::dato[1]/@etiqueta"/>

                    <xsl:choose>
                      <xsl:when test="etiqueta = 'Título'">
                        <xsl:call-template name="imprimeTituloParrafo">
                          <xsl:with-param name="etiqueta" select="etiqueta"></xsl:with-param>
                          <xsl:with-param name="valor" select="valor"></xsl:with-param>
                          <xsl:with-param name="longitud" select="longitud"></xsl:with-param>
                          <xsl:with-param name="comentario" select="comentario"></xsl:with-param>
                          <xsl:with-param name="enlace" select="enlace"></xsl:with-param>
                          <xsl:with-param name="target_enlace" select="target_enlace"></xsl:with-param>
                        </xsl:call-template>
                      </xsl:when>
                      <xsl:when test="etiqueta = 'Subtitulo'">
                        <xsl:call-template name="imprimeSubtituloParrafo">
                          <xsl:with-param name="etiqueta" select="etiqueta"></xsl:with-param>
                          <xsl:with-param name="valor" select="valor"></xsl:with-param>
                          <xsl:with-param name="longitud" select="longitud"></xsl:with-param>
                          <xsl:with-param name="comentario" select="comentario"></xsl:with-param>
                          <xsl:with-param name="enlace" select="enlace"></xsl:with-param>
                          <xsl:with-param name="target_enlace" select="target_enlace"></xsl:with-param>
                        </xsl:call-template>
                      </xsl:when>

                      <xsl:when test="etiqueta = 'Imagen'">
                        <xsl:call-template name="imprimeImagenParrafo">
                          <xsl:with-param name="etiqueta" select="etiqueta"></xsl:with-param>
                          <xsl:with-param name="valor" select="valor"></xsl:with-param>
                          <xsl:with-param name="longitud" select="longitud"></xsl:with-param>
                          <xsl:with-param name="comentario" select="comentario"></xsl:with-param>
                          <xsl:with-param name="enlace" select="enlace"></xsl:with-param>
                          <xsl:with-param name="target_enlace" select="target_enlace"></xsl:with-param>
                        </xsl:call-template>
                      </xsl:when>

                      <xsl:when test="etiqueta = 'Pie Imagen'">
                        <xsl:call-template name="imprimePieImagenParrafo">
                          <xsl:with-param name="etiqueta" select="etiqueta"></xsl:with-param>
                          <xsl:with-param name="valor" select="valor"></xsl:with-param>
                          <xsl:with-param name="longitud" select="longitud"></xsl:with-param>
                          <xsl:with-param name="comentario" select="comentario"></xsl:with-param>
                          <xsl:with-param name="enlace" select="enlace"></xsl:with-param>
                          <xsl:with-param name="target_enlace" select="target_enlace"></xsl:with-param>
                        </xsl:call-template>
                      </xsl:when>

                      <xsl:when test="etiqueta = 'Texto'">
                        <xsl:call-template name="imprimeTextoParrafo">
                          <xsl:with-param name="etiqueta" select="etiqueta"></xsl:with-param>
                          <xsl:with-param name="valor" select="valor"></xsl:with-param>
                          <xsl:with-param name="longitud" select="longitud"></xsl:with-param>
                          <xsl:with-param name="comentario" select="comentario"></xsl:with-param>
                          <xsl:with-param name="enlace" select="enlace"></xsl:with-param>
                          <xsl:with-param name="target_enlace" select="target_enlace"></xsl:with-param>
                        </xsl:call-template>
                      </xsl:when>

                    <xsl:when test="etiqueta = 'Pie Parrafo'">
                      <xsl:call-template name="imprimePieParrafo">
                        <xsl:with-param name="etiqueta" select="etiqueta"></xsl:with-param>
                        <xsl:with-param name="valor" select="valor"></xsl:with-param>
                        <xsl:with-param name="longitud" select="longitud"></xsl:with-param>
                        <xsl:with-param name="comentario" select="comentario"></xsl:with-param>
                        <xsl:with-param name="enlace" select="enlace"></xsl:with-param>
                        <xsl:with-param name="target_enlace" select="target_enlace"></xsl:with-param>
                      </xsl:call-template>
                    </xsl:when>

                    </xsl:choose>
                  </xsl:for-each>
                </div>
              </xsl:when>
            </xsl:choose>
          </xsl:for-each>
        </div>
      </xsl:when>
      <!-- si no hay resultados -->
      <xsl:otherwise>
        <br></br>
        <p style="text-align:center;">El documento no contiene datos.</p>
      </xsl:otherwise>
    </xsl:choose>
 </xsl:template>

  <xsl:template name="imprimeTituloParrafo">
    <xsl:param name="etiqueta"></xsl:param>
    <xsl:param name="valor"></xsl:param>
    <xsl:param name="longitud"></xsl:param>
    <xsl:param name="enlace"></xsl:param>
    <xsl:param name="target_enlace"></xsl:param>

    <h2 class="titulo">
      <xsl:choose>
          <xsl:when test="string-length($enlace) > 0">
            <xsl:call-template name="imprimeEnlace">
              <xsl:with-param name="valor" select="valor"></xsl:with-param>
              <xsl:with-param name="longitud" select="longitud"></xsl:with-param>
              <xsl:with-param name="comentario" select="comentario"></xsl:with-param>
              <xsl:with-param name="enlace" select="enlace"></xsl:with-param>
              <xsl:with-param name="target_enlace" select="target_enlace"></xsl:with-param>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$valor"/>
        </xsl:otherwise>
      </xsl:choose>
    </h2>
  </xsl:template>

  <xsl:template name="imprimeSubtituloParrafo">
    <xsl:param name="etiqueta"></xsl:param>
    <xsl:param name="valor"></xsl:param>
    <xsl:param name="longitud"></xsl:param>
    <xsl:param name="enlace"></xsl:param>
    <xsl:param name="target_enlace"></xsl:param>

    <h3 class="subtitulo">
      <xsl:choose>
        <xsl:when test="string-length($enlace) > 0">
          <xsl:call-template name="imprimeEnlace">
            <xsl:with-param name="valor" select="valor"></xsl:with-param>
            <xsl:with-param name="longitud" select="longitud"></xsl:with-param>
            <xsl:with-param name="comentario" select="comentario"></xsl:with-param>
            <xsl:with-param name="enlace" select="enlace"></xsl:with-param>
            <xsl:with-param name="target_enlace" select="target_enlace"></xsl:with-param>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$valor"/>
        </xsl:otherwise>
      </xsl:choose>
    </h3>
  </xsl:template>

  <xsl:template name="imprimeTextoParrafo">
    <xsl:param name="etiqueta"></xsl:param>
    <xsl:param name="valor"></xsl:param>
    <xsl:param name="longitud"></xsl:param>
    <xsl:param name="enlace"></xsl:param>
    <xsl:param name="target_enlace"></xsl:param>

    <div class="texto">
      <p class="texto">
        <xsl:copy-of select="$valor/node()"/>
      </p>
    </div>
  </xsl:template>

  <xsl:template name="imprimeImagenParrafo">
    <xsl:param name="etiqueta"></xsl:param>
    <xsl:param name="valor"></xsl:param>
    <xsl:param name="longitud"></xsl:param>
    <xsl:param name="comentario"></xsl:param>
    <xsl:param name="enlace"></xsl:param>
    <xsl:param name="target_enlace"></xsl:param>

    <xsl:choose>
      <xsl:when test="string-length($enlace) = 0">
        <xsl:call-template name="imprimeImagen">
          <xsl:with-param name="etiqueta" select="etiqueta"></xsl:with-param>
          <xsl:with-param name="valor" select="valor"></xsl:with-param>
          <xsl:with-param name="longitud" select="longitud"></xsl:with-param>
          <xsl:with-param name="comentario" select="comentario"></xsl:with-param>
          <xsl:with-param name="enlace" select="enlace"></xsl:with-param>
          <xsl:with-param name="target_enlace" select="target_enlace"></xsl:with-param>
        </xsl:call-template>        
      </xsl:when>
      <xsl:otherwise>
        <a>
          <xsl:choose>
            <xsl:when test="$target_enlace/node() = 'E'">
              <xsl:attribute name="target">
                <xsl:text>_blank</xsl:text>
              </xsl:attribute>
            </xsl:when>
            <xsl:when test="$target_enlace/node() = 'I'">
              <xsl:attribute name="target">
                <xsl:text>_self</xsl:text>
              </xsl:attribute>
            </xsl:when>
          </xsl:choose>
          <xsl:attribute name="href">
            <xsl:value-of select="$enlace"/>
          </xsl:attribute>

          <xsl:call-template name="imprimeImagen">
            <xsl:with-param name="etiqueta" select="etiqueta"></xsl:with-param>
            <xsl:with-param name="valor" select="valor"></xsl:with-param>
            <xsl:with-param name="longitud" select="longitud"></xsl:with-param>
            <xsl:with-param name="comentario" select="comentario"></xsl:with-param>
            <xsl:with-param name="enlace" select="enlace"></xsl:with-param>
            <xsl:with-param name="target_enlace" select="target_enlace"></xsl:with-param>
          </xsl:call-template>

        </a>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="imprimeImagen">
    <xsl:param name="etiqueta"></xsl:param>
    <xsl:param name="valor"></xsl:param>
    <xsl:param name="longitud"></xsl:param>
    <xsl:param name="comentario"></xsl:param>
    <xsl:param name="enlace"></xsl:param>
    <xsl:param name="target_enlace"></xsl:param>
    <div class="imagen_pie">
      <img>
        <xsl:attribute name="src">
          <xsl:value-of select="$valor"/>
        </xsl:attribute>
        <xsl:attribute name="alt">
          <xsl:value-of select="$comentario"/>
        </xsl:attribute>
      </img>
    </div>
  </xsl:template>


  <xsl:template name="imprimeEnlace">
    <xsl:param name="valor"></xsl:param>
    <xsl:param name="longitud"></xsl:param>
    <xsl:param name="comentario"></xsl:param>
    <xsl:param name="enlace"></xsl:param>
    <xsl:param name="target_enlace"></xsl:param>
    <a>
      <xsl:choose>
        <xsl:when test="$target_enlace/node() = 'E'">
          <xsl:attribute name="target">
            <xsl:text>_blank</xsl:text>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="$target_enlace/node() = 'I'">
        </xsl:when>
        <xsl:when test="$target_enlace/node() = 'D'">
        </xsl:when>
      </xsl:choose>
      <xsl:attribute name="href">
        <xsl:value-of select="enlace"/>
      </xsl:attribute>
      <xsl:value-of select="$valor"/>
    </a>
  </xsl:template>

 .... 

</xsl:stylesheet>

I need to first apply the template image (if exists in this “PARRAFO”) “Imagen” just before the text “Texto”

Now apply the template text first and then the image because it is before the text node before the image as shown in xml

Thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:21:20+00:00Added an answer on May 15, 2026 at 2:21 am

    You are attempting to write the XML in a ‘procedural’ style, when XML is best written in a ‘declarative’ style. These are known as ‘pull’ and ‘push’ processing. Here’s an example using your data that may help:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="1.0">
      <xsl:output method="html" encoding="iso-8859-1"/>
    
      <xsl:template match="/">
        <rootNode>
          <xsl:apply-templates select="docXML/PARRAFO[@tipo='parrafo']"/>
        </rootNode>
      </xsl:template>
    
      <xsl:template match="PARRAFO[@tipo='parrafo']">
        <div class="parrafo">
        <xsl:apply-templates select="dato[etiqueta='Imagen']"/>
        <xsl:apply-templates select="dato[etiqueta='Texto']"/>
        </div>
      </xsl:template>
    
      <xsl:template match="dato[etiqueta='Imagen']">
        <image></image>
        <!-- processing -->
      </xsl:template>
    
      <xsl:template match="dato[etiqueta='Texto']">
        <text></text>
        <!-- processing -->
      </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to CSS, so please bear with me. I have this form
I'm pretty new to this, so please bear with me. I have a class
I'm still quite new to this so please bear with me. I have a
I'm kind of new to this so please bear with me. I have a
Please bear with me on this as I'm new to this. I have an
I am fairly new to all this, so please bear with me! I have
I am new to bash so please bear with me if this is a
Please bear in mind that I'm totally new to Rails when answering this.My question
I am new to git and if this ques is simple then please bear
I am new to this, so please bear with me... I need to very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.