Hi All,

<client>
<description>KKR</description>
<rits>Test</rits>
<time_zone_code>US/Central</time_zone_code>
<directory_code>Foler</directory_code>
</client>

I need to fetch the above and put it in the form HTML FORM.


Note : Must make use of Xpath,(Identity Transformation)

Dani AI

Generated

A compact, practical XSLT pattern that uses the identity transform and an override to turn each terminal child of the client element into a labelled HTML input. This directly satisfies 's "must use XPath (Identity Transformation)" requirement and provides the sample asked for.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" encoding="UTF-8" indent="yes"/>

  <!-- identity transform: preserves the document by default -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- replace the client element with an HTML form -->
  <xsl:template match="client">
    <form method="post" action="">
      <xsl:apply-templates select="*[not(*)]"/>
    </form>
  </xsl:template>

  <!-- render only terminal children of client as label + input -->
  <xsl:template match="client/*[not(*)]">
    <div>
      <label><xsl:value-of select="local-name()"/></label>
      <input type="text" name="{local-name()}" value="{normalize-space(.)}" />
    </div>
  </xsl:template>

</xsl:stylesheet>

Notes and quick troubleshooting:

  • The identity template preserves everything except where you override (the client template). The client/*[not(*)] template only affects terminal children of client, leaving other parts untouched.
  • To skip empty values, change the apply-templates selector to *[not(*) and normalize-space(.)!=''].
  • If your XML uses a default namespace, bind that namespace in the stylesheet and use the prefixed name (for example ns:client and ns:*[not(*)]).
  • Values are auto-escaped for HTML (preferred). Avoid relying on disable-output-escaping.
  • To test in-browser, reference the stylesheet via an xml-stylesheet PI or run the transform server-side with Saxon/Xalan.
  • If you need different input types (dates, selects), add conditional templates that inspect element names or a mapping table before rendering.

This pattern is compact, reusable, and easy to adapt to variations (namespaces, filtering empty nodes, or different form layouts).

Recommended Answers

All 2 Replies

make a sample to output

H,

Please find the sample o/p file and the related files used for Transformation..

Note ": Please change the extension of Generic.txt to Generic.xsl.
Generic.xml

Generic.txt

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.