help with html table (nested for-each/keys/matched template)
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Sun Dec 18, 2005 12:09 pm
help with html table (nested for-each/keys/matched template)
Greetings,
I am trying to generate an html table that looks through the following xml source and lists links to all of the files (resource-file) and finds the resource-forms that match those file names and adds the appropriate file description next to the link to the filename. The xslt code that I've included doesn't work but gives an idea of what I'm trying to do. Through my research I believe that using keys and/or template matching my be the better way to go, but I'm not sure how to code them. I recognize that the xml structure is a little awkward but that's what I have to work with. Thanks in advance for any suggestions.
XML source
Desired output
Resource File(s) File Description
(link to file1.doc) file1.doc description
(link to file2.doc) file2.doc description
nonworking xslt code
I am trying to generate an html table that looks through the following xml source and lists links to all of the files (resource-file) and finds the resource-forms that match those file names and adds the appropriate file description next to the link to the filename. The xslt code that I've included doesn't work but gives an idea of what I'm trying to do. Through my research I believe that using keys and/or template matching my be the better way to go, but I'm not sure how to code them. I recognize that the xml structure is a little awkward but that's what I have to work with. Thanks in advance for any suggestions.
XML source
Code: Select all
<artifact>
<resource-file>
<artifact>
<displayName>file1.doc</displayName>
<uri>location of file1</uri>
</artifact>
<artifact>
<displayName>file2.doc</displayName>
<uri>location of file2</uri>
</artifact>
</resource-file>
<resource-form>
<file_name>file1.doc</file_name>
<resource_description>file1.doc description</resource_description>
</resource-form>
<resource-form>
<artifact>
<file_name>file2.doc</file_name>
<resource_description>file1.doc description</resource_description>
</artifact>
<artifact>
<file_name>file3.doc</file_name>
<resource_description>file3.doc description</resource_description>
</artifact>
<artifact>
<file_name>file4.doc</file_name>
<resource_description>file4.doc description</resource_description>
</artifact>
</resource-form>
</artifact>
Resource File(s) File Description
(link to file1.doc) file1.doc description
(link to file2.doc) file2.doc description
nonworking xslt code
Code: Select all
<table>
<tr>
<td>Resource File(s)</td>
<td>File Description</td>
</tr>
<tr>
<xsl:for-each select="resource-file/artifact">
<xsl:variable name="filename" select="metaData/displayName"/>
<xsl:variable name="filelocation" select="fileArtifact/uri"/>
<xsl:for-each select="resource-form/artifact"['file_name=$filename']>
<tr>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="$filelocation"/>
</xsl:attribute>
<xsl:attribute name="target">blank</xsl:attribute>
<xsl:value-of select="$filename"/>
</a>
</td>
<td>
<b>Resource Description:</b>
<xsl:value-of select="structuredData/resource-form/resource_description"/>
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</tr>
</table>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
Your stylesheet selects elements that are not even present in your sample XML file. You can find below a working sample (input, stylesheet, result) that may help you.
Best Regards,
George
Your stylesheet selects elements that are not even present in your sample XML file. You can find below a working sample (input, stylesheet, result) that may help you.
Code: Select all
<artifact>
<resource-file>
<artifact>
<displayName>file1.doc</displayName>
<uri>location of file1</uri>
</artifact>
<artifact>
<displayName>file2.doc</displayName>
<uri>location of file2</uri>
</artifact>
</resource-file>
<resource-form>
<artifact>
<file_name>file1.doc</file_name>
<resource_description>file1.doc description</resource_description>
` </artifact>
<artifact>
<file_name>file2.doc</file_name>
<resource_description>file2.doc description</resource_description>
</artifact>
<artifact>
<file_name>file3.doc</file_name>
<resource_description>file3.doc description</resource_description>
</artifact>
<artifact>
<file_name>file4.doc</file_name>
<resource_description>file4.doc description</resource_description>
</artifact>
</resource-form>
</artifact>
Code: Select all
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/artifact">
<table>
<tr>
<td>Resource File(s)</td>
<td>File Description</td>
</tr>
<tr>
<xsl:for-each select="resource-file/artifact">
<xsl:variable name="filename" select="displayName"/>
<xsl:variable name="filelocation" select="uri"/>
<xsl:variable name="description"
select="/artifact/resource-form/artifact[file_name=$filename]/resource_description"/>
<tr>
<td>
<a>
<xsl:attribute name="href">
<xsl:value-of select="$filelocation"/>
</xsl:attribute>
<xsl:attribute name="target">blank</xsl:attribute>
<xsl:value-of select="$filename"/>
</a>
</td>
<td>
<b>Resource Description:</b>
<xsl:value-of select="$description"/>
</td>
</tr>
</xsl:for-each>
</tr>
</table>
</xsl:template>
</xsl:transform>
Code: Select all
Resource File(s) File Description
file1.doc Resource Description:file1.doc description
file2.doc Resource Description:file2.doc description
George
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service