Click here to Skip to main content
15,886,063 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
My xml output looks like this

XML
<Envelope>
 <Header>
  <TimeStamp>2012-08-17T12:04:21-05:00</TimeStamp>
</Header>
</Envelope>


But my file does not have the start element
XML
xml version="1.0" encoding="utf-8"?>


in my code i have given
XML
xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>


How do i display the start element using xslt 2.0
Posted
Updated 17-Aug-12 10:38am
v3

1 solution

test1.xml:

XML
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test1-style.xslt"?>
<Envelope>
  <Header>
    <TimeStamp>2012-08-17T12:04:21-05:00</TimeStamp>
  </Header>
</Envelope>


test1-style.xslt:

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

    <xsl:template match="Envelope/Header">
      <h1><xsl:apply-templates/></h1>
    </xsl:template>

  <xsl:template match="Envelope/Header/TimeStamp">
    <b><xsl:value-of select="."/></b>
  </xsl:template>

    <xsl:template match="/"> <!-- Envelope -->
      <html lang="en">
        <head>
          <title>Test sample</title>
          <style>
            h1 { color: red; }
          </style>
        </head>
        <body>
          <xsl:apply-templates/>
        </body>
      </html>
    </xsl:template>
</xsl:stylesheet>


Output:
2012-08-17T12:04:21-05:00
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900