xml - XSL Transform for Multiple Child Elements -


team

i absolute newbie xslt. trying hand @ automation. want able create following output using below xml code of text:

my xslt

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="3.0"> <xsl:output method="html" version="5.0" encoding="utf-8" indent="yes"/> <xsl:template match="/">     <html>         <head>             <title>kt/definitions list</title>         </head>         <body>             <h2>kt/definitions list</h2>             <table border="1">                 <thead>                     <tr>                         <th>kt</th>                         <th>definition</th>                     </tr>                 </thead>                 <tbody>                         <xsl:apply-templates select="cl:doc//cl:key-term-entry"/>                 </tbody>             </table>         </body>     </html> </xsl:template> <xsl:template match="cl:key-term-entry">     <tr>         <td><xsl:value-of select="cl:key-term"/></td>         <td><xsl:value-of select="cl:key-term-def"/></td>     </tr> </xsl:template> </xsl:stylesheet> 

my part xml input

<cl:key-term-entry identifier="jmtmra930472614"> <cl:key-term identifier="dxykhj261631149">availability sampling</cl:key-term> <cl:key-term-def identifier="bkphvj904214958">a sampling method selects elements because of ready availability , convenience. used in social work because less expensive other methods , because other methods may not feasible particular type of study or population. see <cl:style styles="italic">accidental sampling</cl:style>, <cl:style styles="italic">convenience sampling</cl:style>, , <cl:xref link-target="krjpjv275444397" ordinal="11" pre-text="chapter "/>. </cl:key-term-def> </cl:key-term-entry> 

my xslt output

<tr> <td>availability sampling</td> <td>a sampling method selects elements because of ready availability , convenience. used in social work because less expensive other methods , because other methods may not feasible particular type of study or population. see accidental sampling, convenience sampling, , .</td> </tr> 

my desired xslt output

<tr> <td>availability sampling</td> <td>a sampling method selects elements because of ready availability , convenience. used in social work because less expensive other methods , because other methods may not feasible particular type of study or population. see <i>accidental sampling</i>, <i>convenience sampling</i>, , <a href="chapter11.html">chapter 11</a>.</td> </tr> 

as can see output (not desired output), unable understand how add <i> tags , <a> tag here. in fact, self-closing <cl:xef> tag (whose attribute values have transformed <a> tag) empty in output. here advance knowledge of xslt.

thanks.

update

your answers provided me insight workings of xslt. thank you! however, forgot include question here. want capture information different element in output.

my updated input xml

<cl:chapter identifier="gizwol818406804"> <cl:complex-meta>     <cl:title identifier="fbxqbd997244986">why study research?</cl:title>     <cl:label>chapter <cl:ordinal>1</cl:ordinal></cl:label> </cl:complex-meta> <cl:key-term-entry identifier="jmtmra930472614">     <cl:key-term identifier="dxykhj261631149">availability sampling</cl:key-term>     <cl:key-term-def identifier="bkphvj904214958">a sampling method selects elements because of ready availability , convenience. used in social work because less expensive other methods , because other methods may not feasible particular type of study or population. see         <cl:style styles="italic">accidental sampling</cl:style>,         <cl:style styles="italic">convenience sampling</cl:style>, ,     <cl:xref link-target="krjpjv275444397" ordinal="11" pre-text="chapter "/>.     </cl:key-term-def> </cl:key-term-entry> </cl:chapter> 

my updated part xslt

<xsl:template match="cl:key-term-entry">     <tr>         <td><xsl:apply-templates select="cl:key-term"/></td>         <td><xsl:apply-templates select="cl:key-term-def"/></td>     </tr> </xsl:template> <xsl:template match="//cl:chapter/cl:complex-meta/cl:label">     <td><xsl:value-of select="."/></td> </xsl:template> 

i not sure should include <xsl:apply-templates select="cl:label"/> below desired output.

my new desired output

<tr>                 <td>scientific method</td>                 <td>an approach inquiry attempts safeguard against errors commonly made in casual human inquiry. chief features include viewing knowledge provisional , subject refutation, searching evidence based on systematic , comprehensive observation, pursuing objectivity in observation, , replication. see chapter 1.</td>                 <td>chapter 1</td>  </tr> <tr>...</tr> 

try this:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"  xmlns:cl="http://www.examples"> <xsl:output method="xml" version="5.0" encoding="utf-8" indent="yes"/> <xsl:template match="/">     <html>         <head>             <title>kt/definitions list</title>         </head>         <body>             <h2>kt/definitions list</h2>             <table border="1">                 <thead>                     <tr>                         <th>kt</th>                         <th>definition</th>                     </tr>                 </thead>                 <tbody>                         <xsl:apply-templates select="//cl:key-term-entry"/>                 </tbody>             </table>         </body>     </html> </xsl:template> <xsl:template match="cl:key-term-entry">     <tr>         <td><xsl:apply-templates select="cl:key-term"/></td>         <td><xsl:apply-templates select="cl:key-term-def"/></td>     </tr> </xsl:template>  <xsl:template match="cl:style">     <xsl:choose>         <xsl:when test="@styles='italic'">             <i><xsl:apply-templates/></i>         </xsl:when>         <xsl:when test="@styles='bold'">             <b><xsl:apply-templates/></b>         </xsl:when>         <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>     </xsl:choose> </xsl:template>  <xsl:template match="cl:xref">     <a>         <xsl:attribute name="href">             <xsl:value-of select="concat(normalize-space(@pre-text), @ordinal, '.html')"/>         </xsl:attribute>         <xsl:value-of select="concat(@pre-text, @ordinal)"/>     </a> </xsl:template>   </xsl:stylesheet> 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -