|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
XSLT: Parsing tags with the same name
I'm new to XML/XSLT and I'm a bit stuck. I have the following piece of XML:
Code:
<projects>
<project>
<vpmicode>12345</vpmicode>
<bpm>Jim Beam</bpm>
<project_title>Proj 1</project_title>
<hlr_provided>False</hlr_provided>
<rrb_date>21.03.2004</rrb_date>
<no_visits>1</no_visits>
<p_billing>True</p_billing>
<p_crm>False</p_crm>
<p_portal>False</p_portal>
<p_erp>False</p_erp>
<p_reporting>False</p_reporting>
<p_nm>False</p_nm>
<p_cn>False</p_cn>
<p_net>False</p_net>
<eval_conf>1</eval_conf>
<rfp_required>False</rfp_required>
<fes_complexity>0</fes_complexity>
<eval_cost>2000</eval_cost>
<proj_size>1</proj_size>
<effort_type>1</effort_type>
<reqstombox>01.01.2004</reqstombox>
<fesdate>01.01.2004</fesdate>
<comments>
<comment>Comment 1</comment>
<comment>Comment 2</comment>
<comment>Comment 3</comment>
<comment>Comment 7</comment>
<comment>Comment 9</comment>
</comments>
</project>
...etc.
I have an xslt template trying to parse this. What I don't know how to do is parse the <comment> tags as they have the same name. Anyone got an easy solution for a junior programmer?
Here's the xslt:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="projects">
<HEAD>
<STYLE type='text/css'>
H1 {color=black;font-size:16pt;font-style:bold}
TD {color=green;font-size:10pt}
TH {color=red;font-size:10pt;align=left}
</STYLE>
</HEAD>
<HTML>
<BODY>
<FONT face='Tahoma' size='1'>
<H1>Technical Process Statistics</H1>
<TABLE>
<TR>
<span style='color:red'>
<TH>VPMI Code</TH>
<TH>BPM</TH>
<TH>Project Title</TH>
<TH>HLR</TH>
<TH>T-PIA Date</TH>
<TH>No. Visits</TH>
<TH>Eval. Cof.</TH>
<TH>RFP</TH>
<TH>Cost</TH>
<TH>Size</TH>
<TH>Effort Type</TH>
<TH>Requirements Delivered</TH>
<TH>Feasibility Date</TH>
</span>
</TR>
</TABLE>
<FONT color='black'>
<xsl:for-each select="project">
<TABLE>
<TR>
<TD>
<xsl:value-of select="vpmicode"/>
</TD>
<TD>
<xsl:value-of select="bpm"/>
</TD>
<TD>
<xsl:value-of select="project_title"/>
</TD>
<TD>
<xsl:choose>
<xsl:when test="hlr_provided = 'False'">
No
</xsl:when>
<xsl:otherwise>
Yes
</xsl:otherwise>
</xsl:choose>
</TD>
<TD><xsl:value-of select="rrb_date"/></TD>
<TD><xsl:value-of select="no_visits"/></TD>
<TD>
<xsl:choose>
<xsl:when test="eval_conf = 0">
Low
</xsl:when>
<xsl:when test="eval_conf = 1">
Medium
</xsl:when>
<xsl:otherwise>
High
</xsl:otherwise>
</xsl:choose>
</TD>
<TD>
<xsl:choose>
<xsl:when test="rfp_required = 'False'">No</xsl:when>
<xsl:otherwise>Yes</xsl:otherwise>
</xsl:choose>
</TD>
<TD><xsl:value-of select="eval_cost"/></TD>
<TD>
<xsl:choose>
<xsl:when test='proj_size = 1'>Small</xsl:when>
<xsl:when test='proj_size = 2'>Medium</xsl:when>
<xsl:when test='proj_size = 3'>Large</xsl:when>
<xsl:otherwise>N/A</xsl:otherwise>
</xsl:choose>
</TD>
<TD>
<xsl:choose>
<xsl:when test='effort_type = 1'>Config Change</xsl:when>
<xsl:when test='effort_type = 2'>Enhancement</xsl:when>
<xsl:otherwise>Project</xsl:otherwise>
</xsl:choose>
</TD>
<TD><xsl:value-of select="reqstombox"/></TD>
<TD><xsl:value-of select="fesdate"/></TD>
</TR>
</TABLE>
<TABLE>
<TR><TD>Comments</TD></TR>
<TR><TD><xsl:value-of select="comments/comment"/></TD>
</TR>
</TABLE>
</xsl:for-each>
</FONT>
</FONT>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
Last edited by drgroove : April 20th, 2004 at 04:22 PM. Reason: added code tags; disabled smilies |
|
#2
|
||||
|
||||
|
Code:
<TR><TD>Comments</TD></TR> <TR><TD><xsl:for-each select="comments"><xsl:value-of select="comment" /><br /></xsl:for-each></TD></TR>
__________________
# Jeremy Explain your problem instead of asking how to do what you decided was the solution. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSLT: Parsing tags with the same name |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|