XSLT field validation -


i have requirement validate field content within 1..n structure, data come in pairs of result_id , result_value.

if "<" found in result.min_limit characteristic, value must put in max_limit characteristic target field , min_limit must cleared out in target structure.

sample of source structure data:

<?xml version="1.0" encoding="utf-8"?> <test>     <results>            <result>                 <d_result>                  <d_result_id>result.derived</d_result_id>                  <d_result_value>59w</d_result_value>             </d_result>             <d_result>                  <d_result_id>result.min_limit</d_result_id>                  <d_result_value>&lt;=600.0000</d_result_value>             </d_result>             <d_result>                  <d_result_id>result.max_limit</d_result_id>                  <d_result_value/>             </d_result>             <d_result>                  <d_result_id>result.failedcriticallvl</d_result_id>                  <d_result_value>false</d_result_value>             </d_result>        </result>   </results> </test> 

expected target structure should follow:

<?xml version="1.0" encoding="utf-8"?> <test>   <results>        <result>             <d_result>                  <d_result_id>result.derived</d_result_id>                  <d_result_value>59w</d_result_value>             </d_result>             <d_result>                  <d_result_id>result.min_limit</d_result_id>                  <d_result_value/>             </d_result>             <d_result>                  <d_result_id>result.max_limit</d_result_id>                  <d_result_value>&lt;=600.0000</d_result_value>             </d_result>             <d_result>                  <d_result_id>result.failedcriticallvl</d_result_id>                  <d_result_value>false</d_result_value>             </d_result>        </result>   </results> </test> 

i've created variable store min_limit value if contains "<" character, , works fine when pointer still in min_limit characteristic. when flips next characteristic (max_limit), variable seems loose value , therefore have no visibility of min_limit value anymore assign value max_limit characteristic.

currently, have following:

......

    <xsl:for-each select="a:d_result">         <d_result>             <d_result_id>                 <xsl:value-of select="a:d_result_id"/>             </d_result_id>             <d_result_value>                 <xsl:value-of select="a:d_result_value"/>             </d_result_value>         </d_result>     </xsl:for-each> </result> 

... other fields

i've found interesting conversations here approaches believe solving this, i'm not sure understood enough apply scenario. 1 of xslt: nested for-each , dynamic variable

would suggests solve this?

many in advance! rafael.

here's 1 way @ it:

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>  <!-- identity transform --> <xsl:template match="@*|node()">     <xsl:copy>         <xsl:apply-templates select="@*|node()"/>     </xsl:copy> </xsl:template>  <xsl:template match="d_result_value[../d_result_id='result.min_limit' , contains(., '&lt;')] ">     <xsl:copy/> </xsl:template>  <xsl:template match="d_result_value[../d_result_id='result.max_limit' , contains(../../d_result[d_result_id='result.min_limit']/d_result_value, '&lt;')] ">     <xsl:copy>         <xsl:value-of select="../../d_result[d_result_id='result.min_limit']/d_result_value"/>     </xsl:copy> </xsl:template>  </xsl:stylesheet> 

demo: http://xsltransform.net/3nzcbta


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -