<!-- Main template for escaping strings; used by above template and for object-properties Responsibilities: placed quotes around string, and chain up to next filter, escape-bs-string --> <xsl:template name="escape-string"> <xsl:param name="s" /> <xsl:text>"</xsl:text> <xsl:call-template name="escape-bs-string"> <xsl:with-param name="s" select="$s" /> </xsl:call-template> <xsl:text>"</xsl:text> </xsl:template>
<!-- JS: old version of template, doing the same as escape-bs-string and escape-quot-string together, only more complicated --> <xsl:template name="escape-bs-and-quot-string-in-one-template"> <xsl:param name="s" /> <!-- First handle --> <xsl:choose> <!-- double quote --> <xsl:when test="contains($s,'"') and not(contains($s,'\'))"> <xsl:call-template name="encode-string"> <xsl:with-param name="s" select="substring-before($s,'"')" /> </xsl:call-template> <xsl:text>\"</xsl:text> <xsl:call-template name="escape-string"> <xsl:with-param name="s" select="substring-after($s,'"')" /> </xsl:call-template> </xsl:when> <!-- backslash --> <xsl:when test="not(contains($s,'"')) and contains($s,'\')"> <xsl:call-template name="encode-string"> <xsl:with-param name="s" select="substring-before($s,'\')" /> </xsl:call-template> <xsl:text>\\</xsl:text> <xsl:call-template name="escape-string"> <xsl:with-param name="s" select="substring-after($s,'\')" /> </xsl:call-template> </xsl:when> <xsl:when test="contains($s,'"') and contains($s,'\')"> <xsl:choose> <!-- double quote before backslash --> <xsl:when test="string-length(substring-before($s,'"'))<string-length(substring-before($s,'\'))"> <xsl:call-template name="encode-string"> <xsl:with-param name="s" select="substring-before($s,'"')" /> </xsl:call-template> <xsl:text>\"</xsl:text> <xsl:call-template name="escape-string"> <xsl:with-param name="s" select="substring-after($s,'"')" /> </xsl:call-template> </xsl:when> <!-- backslash before double quote --> <xsl:when test="string-length(substring-before($s,'"'))>string-length(substring-before($s,'\'))"> <xsl:call-template name="encode-string"> <xsl:with-param name="s" select="substring-before($s,'\')" /> </xsl:call-template> <xsl:text>\\</xsl:text> <xsl:call-template name="escape-string"> <xsl:with-param name="s" select="substring-after($s,'\')" /> </xsl:call-template> </xsl:when> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:call-template name="encode-string"> <xsl:with-param name="s" select="$s" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template>
<!-- Replace tab, line feed and/or carriage return by its matching escape code. Also escape tag-close (</tag> to <\/tag> for client-side javascript compliance). Can't escape backslash or double quote here, because they don't replace characters (� becomes \t), but they prefix characters (\ becomes \\). Besides, backslash should be seperate anyway, because it should be processed first. This function can't do that. --> <xsl:template name="encode-string"> <xsl:param name="s" /> <xsl:choose> <!-- tab --> <xsl:when test="contains($s,'	')"> <xsl:call-template name="encode-string"> <xsl:with-param name="s" select="concat(substring-before($s,'	'),'\t',substring-after($s,'	'))" /> </xsl:call-template> </xsl:when> <!-- line feed --> <xsl:when test="contains($s,'
')"> <xsl:call-template name="encode-string"> <xsl:with-param name="s" select="concat(substring-before($s,'
'),'\n',substring-after($s,'
'))" /> </xsl:call-template> </xsl:when> <!-- carriage return --> <xsl:when test="contains($s,'
')"> <xsl:call-template name="encode-string"> <xsl:with-param name="s" select="concat(substring-before($s,'
'),'\r',substring-after($s,'
'))" /> </xsl:call-template> </xsl:when> <!-- JS: tag-close --> <xsl:when test="contains($s,'</')"> <xsl:call-template name="encode-string"> <xsl:with-param name="s" select="concat(substring-before($s,'</'),'<\/',substring-after($s,'</'))" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$s" /> </xsl:otherwise> </xsl:choose> </xsl:template>
<!-- number (no support for javascript mantissa) --> <xsl:template match="text()[not(string(number())='NaN' or (starts-with(.,'0' ) and . != '0'))]"> <xsl:apply-templates select="node()|@*" /> </xsl:template>
</xsl:otherwise> </xsl:choose> <!-- end of type check --> <xsl:if test="following-sibling::*" /> <xsl:if test="not(following-sibling::*)" /> </xsl:template>
<!-- JS: don't quote if not necessary --> <xsl:template name="quote-property"> <xsl:param name="name" /> <xsl:choose> <xsl:when test="contains(',abstract,boolean,break,byte,case,catch,char,class,const,continue,debugger,default,delete,do,double,else,enum,export,extends,final,finally,float,for,function,goto,if,implements,import,in,instanceof,int,interface,long,native,new,package,private,protected,public,return,short,static,super,switch,synchronized,this,throw,throws,transient,try,typeof,var,void,volatile,while,with,',concat(',',$name,',')) or not(translate($name,'.-:','')=$name)"> <xsl:call-template name="escape-string"> <xsl:with-param name="s" select="$name" /> </xsl:call-template> </xsl:when> <xsl:otherwise>
</xsl:otherwise> </xsl:choose> </xsl:template>
<!-- array --> <xsl:template match="*[count(../*[name(../*)=name(.)])=count(../*) and count(../*)>1]"> <xsl:if test="not(preceding-sibling::*)">
<!--<li><xsl:apply-templates select="node()|child::node()|@*" /></li> --> </xsl:otherwise> </xsl:choose> <xsl:if test="following-sibling::*"> <!-- Need to Code here to Make deeper nodes to work,this will work to the deepest node --> <xsl:if test="node()|child::node()|@*">
<!-- JS: indent for reability --> <xsl:template name="indent"> <xsl:text />
<ul> <xsl:for-each select="ancestor::*" /> </ul>
</xsl:template>
<!-- convert root element to an anonymous container -->
</xsl:stylesheet>
When i apply the above written XSL to the XML file i am able to get HTML page.. but the Prob is the way of displaying.
My Parent node is CLIENT it contains few attribuutes and child Node (Application) which in turn contains lots of attributs & nodes (NODES inside NODES).I am able to fetch all elements & node
i Want the OP as
Client Node must be the Master Tab
with in that Master its Child Nodes(Application) & attributes
within Application (it must display its child nodes & attr) like (lockbox_info,bank_relation)
XML to HTML using XSLT
Hi All,
This is gr8 forum, where i can lots & loads of Apprecition.
As of now i am strcuk up with a problem.. while generating HTML page from XML using XSL
XML Structure
When i apply the above written XSL to the XML file i am able to get HTML page.. but the Prob is the way of displaying.
My Parent node is CLIENT it contains few attribuutes and child Node (Application) which in turn contains lots of attributs & nodes (NODES inside NODES).I am able to fetch all elements & node
i Want the OP as
Client Node must be the Master Tab
with in that Master its Child Nodes(Application) & attributes
within Application (it must display its child nodes & attr) like (lockbox_info,bank_relation)
this must keep reapeateds until all done..
Some please help me out :(
Hi Anand, welcome to the forum.
Can't help but think that this is a homework assignment. The XSLT looks like a hacked-up version of "xml2json.xslt" too.
Due to the shear amount of work involved in understanding your XML and XSLT, I doubt anyone on this forum would have time to help you.
If you do need help, my advise is to break your problem down into smaller chunks and we can help you out.
Cheers, Lee.
hi lee,
Thanks for reply,
Yes u r rite ,i did few modification to suit my work.
My Prob:
1. Find all the nodes, elements & attributes of any given XML and display it in the form of Navigation tabs.
My Apporoach:
1. Intially i matched the node name.
like :
Above was fine , until HardCoded node names, attribute name & ele names.Problem was i when i dont have any idea abt the XML file i have
So , i jus took XML2JSON , which was with some problem, made some modification and brought this shape.
Hope i was in right move, untill the XML file was known to me.
Aim of my app is , USER INTERFACE BASED ON XML (100% generic)
is working on a reply...