如何使XSLT以表格格式格式化此导出的xml?

时间:2015-02-26 04:22:02

标签: xml xslt

我是堆叠交换的新手,所以我提前为我可能犯的任何错误道歉... 我从我们的图像管理软件导出了这个xml,我想以表格格式化它。导出允许使用XSL格式化数据,但不提供如何执行此操作的示例。 我希望一旦给出一些指示,这将是一个相当简单的任务。 提前致谢 ... 杰里米

<?xml version="1.1" encoding="UTF-8"?>
<!DOCTYPE Export>
<ns:Export xmlns:ns="http://www.canto.com/ns/Export/1.0">
<ns:Layout tableName="AssetRecords">
    <ns:Fields>
        <ns:Field uid="{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}" type="0" valueInterpretation="0">
            <ns:Name>Record Name</ns:Name>
        </ns:Field>
        <ns:Field uid="{af4b2e43-5f6a-11d2-8f20-0000c0e166dc}" type="0" valueInterpretation="0">
            <ns:Name>Title</ns:Name>
        </ns:Field>
        <ns:Field uid="{0ab76098-1c48-11d5-acb3-00306510d9c9}" type="0" valueInterpretation="0">
            <ns:Name>Accession Number</ns:Name>
        </ns:Field>
        <ns:Field uid="{9aac53db-e086-4d3d-8016-299f73df292e}" type="0" valueInterpretation="0">
            <ns:Name>Artist</ns:Name>
        </ns:Field>
        <ns:Field uid="{3248196a-a576-11d5-8c20-003065ed2114}" type="0" valueInterpretation="0">
            <ns:Name>Vernon</ns:Name>
        </ns:Field>
    </ns:Fields>
</ns:Layout>
<ns:Items>
    <ns:Item catalogid="3" id="320361">
        <ns:FieldValue uid="{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}">Ca102450.tif</ns:FieldValue>
        <ns:FieldValue uid="{af4b2e43-5f6a-11d2-8f20-0000c0e166dc}">Plant forms pendant</ns:FieldValue>
        <ns:FieldValue uid="{0ab76098-1c48-11d5-acb3-00306510d9c9}">2013.133</ns:FieldValue>
        <ns:FieldValue uid="{9aac53db-e086-4d3d-8016-299f73df292e}">INDIAN</ns:FieldValue>
        <ns:FieldValue uid="{3248196a-a576-11d5-8c20-003065ed2114}">109996</ns:FieldValue>
    </ns:Item>
    <ns:Item catalogid="3" id="320587">
        <ns:FieldValue uid="{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}">Ca102453.tif</ns:FieldValue>
        <ns:FieldValue uid="{af4b2e43-5f6a-11d2-8f20-0000c0e166dc}">Horse and rider pendant</ns:FieldValue>
        <ns:FieldValue uid="{0ab76098-1c48-11d5-acb3-00306510d9c9}">2013.212</ns:FieldValue>
        <ns:FieldValue uid="{9aac53db-e086-4d3d-8016-299f73df292e}">INDIAN</ns:FieldValue>
        <ns:FieldValue uid="{3248196a-a576-11d5-8c20-003065ed2114}">110102</ns:FieldValue>
    </ns:Item>
    <ns:Item catalogid="3" id="320612">
        <ns:FieldValue uid="{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}">Ca102455.tif</ns:FieldValue>
        <ns:FieldValue uid="{af4b2e43-5f6a-11d2-8f20-0000c0e166dc}">Durga pendant</ns:FieldValue>
        <ns:FieldValue uid="{0ab76098-1c48-11d5-acb3-00306510d9c9}">2013.238</ns:FieldValue>
        <ns:FieldValue uid="{9aac53db-e086-4d3d-8016-299f73df292e}">INDIAN</ns:FieldValue>
        <ns:FieldValue uid="{3248196a-a576-11d5-8c20-003065ed2114}">110129</ns:FieldValue>
    </ns:Item>
    <ns:Item catalogid="3" id="320596">
        <ns:FieldValue uid="{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}">Ca102458.tif</ns:FieldValue>
        <ns:FieldValue uid="{af4b2e43-5f6a-11d2-8f20-0000c0e166dc}">Horse and rider mould</ns:FieldValue>
        <ns:FieldValue uid="{0ab76098-1c48-11d5-acb3-00306510d9c9}">2013.221</ns:FieldValue>
        <ns:FieldValue uid="{9aac53db-e086-4d3d-8016-299f73df292e}">INDIAN</ns:FieldValue>
        <ns:FieldValue uid="{3248196a-a576-11d5-8c20-003065ed2114}">110113</ns:FieldValue>
    </ns:Item>
    <ns:Item catalogid="3" id="320610">
        <ns:FieldValue uid="{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}">Ca102461.tif</ns:FieldValue>
        <ns:FieldValue uid="{af4b2e43-5f6a-11d2-8f20-0000c0e166dc}">Durga mould</ns:FieldValue>
        <ns:FieldValue uid="{0ab76098-1c48-11d5-acb3-00306510d9c9}">2013.236</ns:FieldValue>
        <ns:FieldValue uid="{9aac53db-e086-4d3d-8016-299f73df292e}">INDIAN</ns:FieldValue>
        <ns:FieldValue uid="{3248196a-a576-11d5-8c20-003065ed2114}">110127</ns:FieldValue>
    </ns:Item>
    <ns:Item catalogid="3" id="320622">
        <ns:FieldValue uid="{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}">Ca102463.tif</ns:FieldValue>
        <ns:FieldValue uid="{af4b2e43-5f6a-11d2-8f20-0000c0e166dc}">Surya pendant</ns:FieldValue>
        <ns:FieldValue uid="{0ab76098-1c48-11d5-acb3-00306510d9c9}">2013.248</ns:FieldValue>
        <ns:FieldValue uid="{9aac53db-e086-4d3d-8016-299f73df292e}">INDIAN</ns:FieldValue>
        <ns:FieldValue uid="{3248196a-a576-11d5-8c20-003065ed2114}">110140</ns:FieldValue>
    </ns:Item>
    <ns:Item catalogid="3" id="320492">
        <ns:FieldValue uid="{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}">Ca102466.tif</ns:FieldValue>
        <ns:FieldValue uid="{af4b2e43-5f6a-11d2-8f20-0000c0e166dc}">Ganesh mould</ns:FieldValue>
        <ns:FieldValue uid="{0ab76098-1c48-11d5-acb3-00306510d9c9}">2013.117</ns:FieldValue>
        <ns:FieldValue uid="{9aac53db-e086-4d3d-8016-299f73df292e}">INDIAN</ns:FieldValue>
        <ns:FieldValue uid="{3248196a-a576-11d5-8c20-003065ed2114}">109980</ns:FieldValue>
    </ns:Item>
    <ns:Item catalogid="3" id="320623">
        <ns:FieldValue uid="{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}">Ca102468.tif</ns:FieldValue>
        <ns:FieldValue uid="{af4b2e43-5f6a-11d2-8f20-0000c0e166dc}">Figure mould</ns:FieldValue>
        <ns:FieldValue uid="{0ab76098-1c48-11d5-acb3-00306510d9c9}">2013.249</ns:FieldValue>
        <ns:FieldValue uid="{9aac53db-e086-4d3d-8016-299f73df292e}">INDIAN</ns:FieldValue>
        <ns:FieldValue uid="{3248196a-a576-11d5-8c20-003065ed2114}">110141</ns:FieldValue>
    </ns:Item>
    <ns:Item catalogid="3" id="320458">
        <ns:FieldValue uid="{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}">Ca102470.tif</ns:FieldValue>
        <ns:FieldValue uid="{af4b2e43-5f6a-11d2-8f20-0000c0e166dc}">Shiva and Parvati on horseback mould</ns:FieldValue>
        <ns:FieldValue uid="{0ab76098-1c48-11d5-acb3-00306510d9c9}">2013.231</ns:FieldValue>
        <ns:FieldValue uid="{9aac53db-e086-4d3d-8016-299f73df292e}">INDIAN</ns:FieldValue>
        <ns:FieldValue uid="{3248196a-a576-11d5-8c20-003065ed2114}">110122</ns:FieldValue>
    </ns:Item>
    <ns:Item catalogid="3" id="320366">
        <ns:FieldValue uid="{af4b2e00-5f6a-11d2-8f20-0000c0e166dc}">Ca102474.tif</ns:FieldValue>
        <ns:FieldValue uid="{af4b2e43-5f6a-11d2-8f20-0000c0e166dc}">Hanuman mould</ns:FieldValue>
        <ns:FieldValue uid="{0ab76098-1c48-11d5-acb3-00306510d9c9}">2013.138</ns:FieldValue>
        <ns:FieldValue uid="{9aac53db-e086-4d3d-8016-299f73df292e}">INDIAN</ns:FieldValue>
        <ns:FieldValue uid="{3248196a-a576-11d5-8c20-003065ed2114}">110001</ns:FieldValue>
    </ns:Item>
</ns:Items>
</ns:Export>

我想要按行格式化数据......

Record Name  Title                   Accession Number    Artist    Vernon
Ca102450     Plant forms pendant     2013.133            Indian    109996
Ca102453     Horse and rider pendant 2013.212            Indian    110102
etc

1 个答案:

答案 0 :(得分:0)

首先,欢迎来到堆栈溢出,我们可以真正探索,分享许多想法并解决我们的问题。

使用XML转换下面的XSLT时,您将获得表格格式

<强> XSLT:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="http://www.canto.com/ns/Export/1.0" exclude-result-prefixes="ns">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="ns:Export"><table xmlns:ns="http://www.canto.com/ns/Export/1.0"><xsl:apply-templates/></table></xsl:template>
<xsl:template match="ns:Fields"><thead><tr><xsl:apply-templates/></tr></thead></xsl:template>
<xsl:template match="ns:Field/ns:Name"><td><xsl:apply-templates/></td></xsl:template>
<xsl:template match="ns:Items"><tbody><xsl:apply-templates/></tbody></xsl:template>
<xsl:template match="ns:Item"><tr><xsl:apply-templates/></tr></xsl:template>
<xsl:template match="ns:FieldValue"><td><xsl:apply-templates/></td></xsl:template>
</xsl:stylesheet>