I’m looking for a way to output this code as html.
<legal>
<heading>Poo</heading>
<g>fart <a href="http://www.bclaws.ca/EPLibraries/bclaws_new/document/ID/freeside/96165_01">Freedom of Information and Protection of Privacy Act</a> (RSBC 1996 ch. 165):</g>
<foo>
<bar>a </bar>
<bar>b </bar>
<bar>c </bar>
<bar>d </bar>
<bar>e </bar>
<bar>f </bar>
</foo>
<g> faf </g>
<g> faf </g>
<g> faf </g>
<g> faf </g>
<g> faf </g>
<g> faf </g>
<g> faf </g>
<foo>
<bar> a </bar>
<bar> b </bar>
<bar> c </bar>
</foo>
<g> asfd </g>
<g> asfd </g>
<g> asfd </g>
<g> asfd </g>
<g> asfd </g>
<g> asfd </g>
<g> asfd </g>
<foo>
<bar> a </bar>
<bar> b </bar>
<bar> c </bar>
</foo>
</legal>
Here is my XSLT so far… I cannot seem to output each and every g element within the p tags… it only seems to output it once and never again. Also, I seem to only be outputting the same thing twice… Where am I going wrong?
<xsl:variable name="legal" select="document('legal.xml')/legal"/>
<xsl:for-each select="$legal/heading">
<h3><xsl:value-of select="$legal/heading"/></h3>
<p><xsl:value-of select="$legal/g"/></p>
<ul>
<xsl:for-each select="$legal/foo/bar">
<li><xsl:value-of select="."/></li>
</xsl:for-each>
</ul>
</xsl:for-each>
I’d suggest replacing the entire code fragment you’ve shown with this:
and adding these templates:
The reason you’re getting duplicates at the moment is because you’re iterating over each header, and then in each iteration of that loop, you’re processing the same
gelement, and iterating over the samefooelements, regardless of which header they’re after. In both your source and the html output,g/pelements are not children ofheader/h3elements, it doesn’t make sense to treat them as such in your code.