2

Document:

<?xml version="1.0" encoding="utf-8"?>
<page>
    <tab dim="30">
        <column>

        </column>
        <column>

        </column>
    </tab>
    <tab dim="70">
    </tab>
</page>

stylesheet:

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
    <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html></xsl:text>
    <html>
    <head>

    </head>
    <body>
        <xsl:for-each select="tab">
        <div class="tab">tab</div>
        </xsl:for-each>
    </body>
    </html>
</xsl:template>

</xsl:stylesheet>

producing this

<!DOCTYPE html><html><head></head><body></body></html>

I want this

<!DOCTYPE html><html><head></head><body><div class="tab">tab</div><div class="tab">tab</div></body></html>

2 Answers 2

1

You need

<xsl:for-each select="page/tab">

instead of

<xsl:for-each select="tab">

Either that, or you could do

<xsl:template match="/page">

instead of

<xsl:template match="/">
Sign up to request clarification or add additional context in comments.

Comments

0

I would use template matching for <tab> – and for <page>

<xsl:template match="page">
  <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html&gt;</xsl:text>
  <html>
    <head></head>
    <body>
      <xsl:apply-templates/>
    </body>
  </html>
</xsl:template>

<xsl:template match="tab">
  <div class="tab">tab</div>
</xsl:template>

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.