xml - xslt seeking text from a parent node -


i hope able answer other peoples questions soon, in meantime hope may able answer mine.

here sample xml file have...

  <tr layoutcode="" type="categoryhead" level="2">     <td colname="1">common stocks 87.33%[this tag]</td>    (b)     <td colname="2"/>     <td colname="3"/>     <td colname="4"/>     <td colname="5"/>   </tr>   <tr layoutcode="" type="categoryhead" level="3">     <td colname="1">&lt;2&gt;health care&amp;lt;softreturn&amp;gt;21.27%</td>     <td colname="2"/>     <td colname="3"/>     <td colname="4"/>     <td colname="5"/>   </tr>   <tr layoutcode="" type="detail" level="4">     <td colname="1"/>     <td colname="2">gillan sciences [asset type]</td>  (a)     <td colname="3">26,522,142</td>     <td colname="4">1,132,761</td>     <td colname="5">4.12</td>   </tr> 

.... , take 'td' tag, represented here (a) , replace text 'asset type' text first parent 'tr' node has attribute of type="categoryhead" , child 'td' node containg text 'this tag' represented here (b). in other words original xml has 'gillan sciences [asset type]' display 'gillan sciences common stocks'.

this have far, xslt file if parent node immediate parent or if specify 'level' attribute. ideally query able swim upwards until finds first 'tr' parent node type of 'categoryhead' , child 'td' node 'this tag' in text.....

<xsl:template match="@*|node()"> <xsl:copy>          <xsl:apply-templates select="@*|node()"/> </xsl:copy>  </xsl:template>   <xsl:template match="v4:td[contains(text(),'asset type')]/text()">           <xsl:variable name="replacementtag" select="'asset type'"></xsl:variable>     <xsl:variable name="lev" select="../@level"/>     <xsl:call-template name="replace-this">         <xsl:with-param name="text" select="."/>         <xsl:with-param name="replace" select="$replacementtag" />         <xsl:with-param name="by" select="../../preceding-sibling::v4:tr[@type = 'categoryhead'][1]/v4:td[contains(text(), 'this tag')]/text()" />     </xsl:call-template> </xsl:template> 

the 'v4' abbreviation of namespace using way.

any ideas appreciated. many thanks, alex.

the next xslt of job, won't remove 87.33% text:

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:pref="http://example.org/uri" xmlns="http://example.org/uri" exclude-result-prefixes="pref">     <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>      <xsl:template match="@*|node()">         <xsl:copy>             <xsl:apply-templates select="@*|node()" />         </xsl:copy>     </xsl:template>      <xsl:template match="pref:tr[@type = 'detail']/pref:td[contains(., '[asset type]')]">         <xsl:copy>             <xsl:apply-templates select="@*" />             <xsl:value-of select="substring-before(., '[asset type]')" />             <xsl:value-of select="substring-before((preceding::pref:tr[@type = 'categoryhead']/pref:td[contains(., '[this tag]')])[last()], '[this tag]')" />         </xsl:copy>     </xsl:template> </xsl:stylesheet> 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -