0

I am trying to transform xml using xslt; however, I am getting a blank response. Below is my input xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<add>
    <page>
        <title>3Days 2Night Chiang Mai to Chiang Rai</title>
        <id>83509</id>
        <revision>
            <id>1305791</id>
            <timestamp>2009-11-27T10:35:53Z</timestamp>
            <contributor>
                <username>Texugo</username>
                <id>7666</id>
                <realname />
            </contributor>
            <comment>moved to</comment>
            <text xml:space="preserve">hello</text>
        </revision>
    </page>
</add>

I want to transform the above input file to the following output format:

<?xml version="1.0" encoding="UTF-8"?>
<page>
   <title>3Days 2Night Chiang Mai to Chiang Rai</title>
   <id>83509</id>
   <tex>hello<text>
   <comment>moved to</comment>
</page>

Below is the XSL which i have written:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent ="yes"/>
    <xsl:template match="/page" >
    <page>
    <title><xsl:value-of select="title"/></title>
    <id><xsl:value-of select="id"/></id>
    <text><xsl:value-of select="revision/text" /></text>
    <comment><xsl:value-of select="revision/comment" /></comment>
    </page>
    </xsl:template>
</xsl:stylesheet>

However, I am just getting the xml skeleton with no values inside the elements. Please help!!

1 Answer 1

1

/page selects the root element page, which is incorrect in your case. Try /add/page or just page:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/add/page">
        <page>
            <title>
                <xsl:value-of select="title"/>
            </title>
            <id>
                <xsl:value-of select="id"/>
            </id>
            <text>
                <xsl:value-of select="revision/text"/>
            </text>
            <comment>
                <xsl:value-of select="revision/comment"/>
            </comment>
        </page>
    </xsl:template>
</xsl:stylesheet>
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.