javascript - simple xml attribute value get the using xslt in the html file -
the xml file this:-
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="final.xsl"?> <root> <child1 entity_id = "1" value= "asia"> <child2 entity_id = "2" value = "india"> <child3 entity_id = "3" value = "gujarat"> <child5 entity_id = "5" value ="rajkot"></child5> </child3> <child4 entity_id = "4" value = "rajshthan"> <child6 entity_id = "6" value = "ajmer"></child6> </child4> </child2> </child1> </root>
this xslt code:-
<xsl:for-each select="//child2"> <xsl:value-of select="@value" /> </xsl:for-each>
this output:-
republic of india
i want output in html file how can possible please help me out of this
this xslt display children of item matches value of region
parameter:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="html" encoding="utf-8"/> <xsl:key name="kchild" match="*[@value]" use="../@value"/> <xsl:param name="region" select="'india'" /> <xsl:template match="/"> <xsl:apply-templates select="key('kchild', $region)" /> </xsl:template> <xsl:template match="*"> <xsl:value-of select="@value"/> <xsl:text>
</xsl:text> </xsl:template> </xsl:stylesheet>
for example, if default value "india" used, output be:
gujarat rajshthan
if value "asia" used, output be:
india
in order pass parameter xslt, think you'll need utilize javascript in web page apply xslt instead of having applied automatically.
here page code showing how apply xslt in javascript, , how pass parameters it:
http://www.articlejobber.com/tutorial/javascript_xslt_parameters_20060303_2.html
javascript jquery xml xslt xpath
No comments:
Post a Comment