How to read tag names from xml at any depth using xslt and How to segregate all the tag names and use as columns in table for SQL insert statement.? -
how read tag names xml @ depth using xslt?
how segregate tag names , use columns in table sql insert statement.
need xslt generate insert statement using xml tags columns table
<xxx> <123> <sss>12</sss> <zzz>111</zzz> <aaa> <qqq>000</qqq> <q11>000</q12> <q22>333</q22> </aaa> <bbb> <lll>888</lll> <dd>eee</ddd> <111> <ss1>123</ss1> <vvv>777<vvv> <111> </bbb> </123> </xxx>
insert sampletable(sss, zzz, qqq, q11, q22, lll, dd, ss1, vvv) values(12, 111, 000, 000, 333, 888, eee, 123, 777).
need output.
the below xpath, after required customization, need:
concat( 'insert sampletable(', string-join((for $var in //*[not(*)] return name($var)),','), ') values(', string-join((for $var in //*[not(*)] return $var),','), ')')
xslt-2.0:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema" version="2.0"> <xsl:output method="text" encoding="utf-8"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:value-of select="concat( 'insert sample table(', string-join((for $var in //*[not(*)] return name($var)),','), ') values(', string-join((for $var in //*[not(*)] return $var),','), ')')"/> </xsl:template> </xsl:stylesheet>
the above xslt, input provides below output:
insert sample table(sss,zzz,qqq,q11,q22,lll,dd,ss1,vvv) values(12,,000,000,333,888,eee,123,777)
explanation:
with xpath, for $var in //*[not(*)] return name($var)
, iterating on every element in whole document(that doesn't have child element) , returning it's name()
. in same way, in later for
returning values.
string-join()
concat sequence of items returned commas.
Comments
Post a Comment