java - Coloring occasional lines in full XML Structure and show in HTML -


my first question marked duplicated, isn't duplicate

show xml in html inline stylesheet

i hope question not immediatley marked duplicate, because 1 of moderators has read first 2 sentences and've ignored rest.

the problem not show xml structure in html, rather show full dynamically xml structure, tags , occasional colored lines. structure , interior fields full dynamically , every field can correct or wrong, depending on xml file compare. field @ first comparison correct, on comparison it’s wrong. fields , structure of xml can vary 1 comparison another. i’m looking since yesterday corresponding , professional solution problem. background process: comparison different xml files, via soa microservices in java. comparison made org.custommonkey.xmlunit. result have html popup, shows me differences marked colored lines.

example output xunit diff result xpath

/root[1]/matdetail[1]/output[1]/general[1]/changed_by[1]/text()[1] 

transform source xml via xslt , xunit diff result informations.

example input xml

<root>           <matdetail>             <output>                   <general>                         <created_on/>                         <created_by>original user</created_by>                         <last_chnge/>                         <changed_by>new user</changed_by>                   </general>                   <return>                         <type>s</type>                         <message/>                         <log_no/>                         <log_msg_no>000000</log_msg_no>                   </return>             </output>       </matdetail>   </root> 

example xsl transformation

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:template match="node() | @*"> <xsl:copy> <xsl:apply-templates select="node() | @*" mode="unescape"/> </xsl:copy> </xsl:template> <xsl:template match="/root[1]/matdetail[1]/output[1]/general[1]/changed_by[1]">      <xsl:element name = "span">         <xsl:attribute name="style">font-weight:bold; color:red </xsl:attribute>         <xsl:copy>             <xsl:value-of select = "current()" />         </xsl:copy>         <xsl:text>&lt;== expected: dasda</xsl:text>     </xsl:element> </xsl:template> </xsl:stylesheet> 

example result of xsl transformation

<root>           <matdetail>             <output>                   <general>                         <created_on/>                         <created_by>original user</created_by>                         <last_chnge/>                         <span style="font-weight:bold; color:red "><changed_by>new user</changed_by>&lt;== expected: original user</span>                   </general>                   <return>                         <type>s</type>                         <message/>                         <log_no/>                         <log_msg_no>000000</log_msg_no>                   </return>             </output>       </matdetail>   </root> 

i’m not able show xml structure in html, with (all) tags, correctly and colored. either i’ve no tags, there raw data in xml see, without tags, lines colored. or xml structure data, not colored. tried replace lt , gt chars inside xslt, failed, or after transformation in java, result shows ugly. colleague has meant can not use in way. because xml structur can every time different , on dynamically, can not style xml css , tag definition. unfortunately, alternative implementations not option. have somehow means available me. (java, xml & xsl, js, html, css).

i hope ideas solute this.

i thank in advance.

i hope can solve issue following try.

i. input:

<root baum="baum">         <matdetail>         <output>             <general>                 <created_on/>                 <created_by>original user</created_by>                 <last_chnge/>                 <changed_by>new user</changed_by>             </general>             <return>                 <type>s</type>                 <message/>                 <log_no/>                 <log_msg_no>000000</log_msg_no>             </return>         </output>     </matdetail>   </root> 

ii. stylesheet (xslt 1.0):

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform"     version="1.0">      <xsl:output omit-xml-declaration="yes"/>      <xsl:template match="/">         <xsl:apply-templates />     </xsl:template>      <xsl:template match="changed_by">         <span style="color:red;">             <xsl:apply-templates select="." mode="serialize"/>         </span>     </xsl:template>      <xsl:template match="*">         <xsl:apply-templates select="." mode="serialize"/>     </xsl:template>      <xsl:template match="@*">         <xsl:apply-templates select="." mode="serialize"/>     </xsl:template>      <xsl:template match="*" mode="serialize">         <xsl:value-of select="concat('&lt;', name())"/>         <xsl:apply-templates select="@*" />         <xsl:choose>             <xsl:when test="node()">                 <xsl:text>&gt;</xsl:text>                 <xsl:apply-templates />                 <xsl:value-of select="concat('&lt;', name(), '&gt;')"/>             </xsl:when>             <xsl:otherwise>                 <xsl:text> /&gt;</xsl:text>             </xsl:otherwise>         </xsl:choose>     </xsl:template>      <xsl:template match="@*" mode="serialize">         <xsl:value-of select="concat(' ', name(), '=&quot;', ., '&quot;')"/>     </xsl:template>      <xsl:template match="text()" mode="serialize">         <xsl:value-of select="."/>     </xsl:template>  </xsl:stylesheet> 

iii: output:

&lt;root baum="baum"&gt;         &lt;matdetail&gt;         &lt;output&gt;             &lt;general&gt;                 &lt;created_on /&gt;                 &lt;created_by&gt;original user&lt;/created_by&gt;                 &lt;last_chnge /&gt;                 <span style="color:red;">&lt;changed_by&gt;new user&lt;/changed_by&gt;</span>             &lt;/general&gt;             &lt;return&gt;                 &lt;type&gt;s&lt;/type&gt;                 &lt;message /&gt;                 &lt;log_no /&gt;                 &lt;log_msg_no&gt;000000&lt;/log_msg_no&gt;             &lt;/return&gt;         &lt;/output&gt;     &lt;/matdetail&gt;   &lt;/root&gt; 

iv. explanation:

whenever mode="serialize" applied, context escaped. see example changed_by format html-tags. xml structure escaped browser shows string instead of tags.

i hope solves problem


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -