I have an HTML file and i want to convert to XML document only using XSLT..
I want:
- All the nodes to be retained.
- And all elements are sorted.
- And code should be in dynamically.
- i have an comma(,)between the elements so i need to handle that as delimiter like
<dl>,</dl>as where it comes..(not only comma some speces also want to retained)
i have an huge file so i want an simple code to process all the html nodes.here i explained my codeing with the xslt
if u understand it plz help me..
My HTML file is..
<span id="2102" class="one_biblio">
<span id="2103" class="one_section-title"><b>Title</b></span>
<span id="2204" class="one_authors">
<span id="2205" class="one_author">, <!--here the comma arraives-->
<!-- here the id value misplaced -->
<span id="2207" class="one_surname">Surname</span>,<!--here the comma arraives-->
<span id="2206" class="one_given-name">GivenName</span>,<!--here the comma arraives-->
</span>
</span>
<span id="2208" class="one_title">
<span id="2209" class="one_maintitle">technology</span>
</span>
And i want the Output XML file as:
Here the attribute class value is used as element name.
And the elements to be sorted.
And the comma(,) should be come within the delimiter tag.
<biblio id="2102" >
<section-title id="2103" ><b>Title</b></section-title>
<authors id="2204" >
<author id="2205" >
<dl>,</dl> <!--here i want like this-->
<!-- correrct the id -->
<given-name id="2206" >GivenName </given-name><dl>,</dl><!--here i want like this-->
<surname id="2207" >Surname</surname><dl>,</dl><!--here i want like this-->
</author>
</authors>
<title id="2208" >
<maintitle id="2209" >technology</maintitle>
</title>
</biblio>
The XSLT i wrote is ..
<xsl:template match="*[@class]">
<xsl:element name="{substring-after(@class, 'mps_')}">
<xsl:copy-of select="@*[not(name()='class')]"/>
<xsl:if test="not(current())">
<xsl:apply-templates>
<xsl:sort select="@id" data-type="number"/>
</xsl:apply-templates>
</xsl:if>
</xsl:element>
</xsl:template>
Help me.......
This XSLT 1.0 transformation:
when applied on the provided XML document (corrected to be made well-formed !!!):
produces the wanted, correct result:
Explanation: Two-pass transformation. The first pass fixes the comma, the second pass does the rest of the processing.