首页 \ 问答 \ 如何使用XSLT匹配元素和输出HTML?(How to match elements and output HTML using XSLT?)

如何使用XSLT匹配元素和输出HTML?(How to match elements and output HTML using XSLT?)

http://s6.postimg.org/5zzsratqp/output.jpg < - 预期输出 - >

下面是我给出的XML文件,我需要使用HTML,CSS,Javascript和XSLT以表格形式显示数据。 然而,找到标签是具有挑战性的,并且使用我创建的样式表,没有任何东西出现。 任何建议? 谢谢

XML数据

<?xml-stylesheet type="text/xsl" href="stylesheet.xsl"?>
<data>
    <object instance="197784" dataInstance="41" name="Give As You Earn Flex" itemNumber="1" pageNumber="1" pagesAvailable="1">
        <property id="{00fd4f20-8e9c-414f-b34f-2abd4a4dc3fe}" name="Effective Date">
            <format id="{332f8155-7253-4dc9-896c-61a3a3d19816}" answer="30/05/2014 13:39:55" />
        </property>
        <property id="{ea61f121-1c2b-47df-91af-3806eba65c4b}" name="Benefit Type ID">
            <format id="{05b7ea73-a86f-4119-b330-0a0f5a4e0143}" answer="GAYE" />
        </property>
        <object instance="197785" dataInstance="41" name="Default (GAYE)" itemNumber="1" pageNumber="1" pagesAvailable="1">
            <property id="{7f428c44-7800-4972-ad37-a005824c251f}" name="Flex Default Amount">
                <format id="{4cf95889-2249-4270-9ce0-9e2da5fedbb7}" answer="0" />
            </property>
            <property id="{cc70d36d-5700-41bf-9370-2ec34c6c7010}" name="Flex Default Cost">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
        </object>
        <object instance="197786" dataInstance="41" name="Model (GAYE)" itemNumber="1" pageNumber="1" pagesAvailable="1">
            <property id="{ea123f721-1c2b-47df-91af-3806eba65c4b}" name="Chosen Charity">
                <format id="{05b7ea73-a86f-4119-b330-0a0f5a4e0143}" answer="" />
            </property>
            <property id="{bf500440-3f1a-46ea-8937-1d8c4dfea274}" name="Flex Model Amount">
                <format id="{4cf95889-2249-4270-9ce0-9e2da5fedbb7}" answer="0" />
            </property>
            <property id="{bf9af022-ba8b-46ed-b043-573c01ba2e1d}" name="Flex Model Cost">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
            <property id="{2d94fe41-8492-4c5d-945a-a23bb5dfcf93}" name="Amount Liable for Tax">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
            <property id="{8555974b-b80e-4704-9241-867cbb435523}" name="Amount Liable for NI">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
        </object>
        <object instance="197787" dataInstance="41" name="Requested (GAYE)" itemNumber="1" pageNumber="1" pagesAvailable="1">
            <property id="{0a113492-faed-4c6e-be73-d6c14210f0b3}" name="Flex Requested Amount">
                <format id="{4cf95889-2249-4270-9ce0-9e2da5fedbb7}" answer="0" />
            </property>
            <property id="{28db97f2-9346-498d-b0b7-724535af30c4}" name="Flex Requested Cost">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
        </object>
        <object instance="197788" dataInstance="41" name="Current (GAYE)" itemNumber="1" pageNumber="1" pagesAvailable="1">
            <property id="{b0424854-bbf4-4299-080e-2480e6c09172}" name="Flex Current Amount">
                <format id="{4cf95889-2249-4270-9ce0-9e2da5fedbb7}" answer="0" />
            </property>
            <property id="{2cb5ac07-a5c7-4bfd-9b15-925a6dd5ba6c}" name="Flex Current Discount Amount">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
            <property id="{b8a7f2fe-9590-44ca-bc3d-027c76ff3dff}" name="Flex Current Value">
                <format id="{05b7ea73-a86f-4119-b330-0a0f5a4e0143}" answer="0" />
            </property>
            <property id="{e133d446-443a-419e-812f-f6506f0101db}" name="Flex Current VAT Amount">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
            <property id="{16d1795a-ad48-401e-9dc4-68f76310e238}" name="Flex Current Cost">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
        </object>
        <Object_ID ObjectName="Give As You Earn Flex" ParentDataInstance="47" ParentObjectInstance="197759" EmployeeObjectInstance="197993" EmployeeDataInstance="47" />
        <ChildObject_ID ChildObjectName="Default (GAYE)" ChildObjectInstance="197785" />
        <ChildObject_ID ChildObjectName="Model (GAYE)" ChildObjectInstance="197786" />
        <ChildObject_ID ChildObjectName="Requested (GAYE)" ChildObjectInstance="197787" />
        <ChildObject_ID ChildObjectName="Current (GAYE)" ChildObjectInstance="197788" />
    </object>
    <variables>
        <variable type="request.querystring" name="DP" value="47:197738/47:197759/41:197784" />
        <variable type="request.querystring" name="select" value="true" />
        <variable type="ID" name="UserRole" value="Employee" />
        <variable type="date" fulldate="14/08/2014 10:17:13" ukdate="14 August 2014" shortdate="14/08/2014" year="2014" month="8" monthname="August" day="14" timeGMT="14/08/2014 09:17:13" time="14/08/2014 10:17:13" />
    </variables>
    <options mode="Any Value" type="CoverLevel" inputName="Flex Model Amount|197786|41" modelValue="0" modelAdditionalValue="" currentValue="0" currentAdditionalValue="" formatting="Currency" suffix="Donation" minimum="1" maximum="11666.67" increment="0.01" charityName="">
        <selectionText>Please select the amount that you would like to donate per pay period:</selectionText>
        <additionalSelectionText />
        <onChange>
            validateDependants('',this.value,'No');toggleDeclarationBox(this.value)
        </onChange>
        <option value="0" location="0" cost="00" alias="No Donation" validation="No Cover" />
    </options>
</data>

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="/">
  <html>
  <body>
  <h2>testing</h2>
     <xsl:for-each select="data">
      <xsl:value-of select="name"/>
        <xsl:value-of select="property"/>
        <xsl:value-of select="format"/>
      </xsl:for-each>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

http://s6.postimg.org/5zzsratqp/output.jpg <--EXPECTED OUTPUT-->

Below is an XML file I have been given, whereby I need to display the data in a form using HTML, CSS, Javascript & XSLT. However, finding the tags are challenging, and with the stylesheet I have created, nothing is appearing. Any advice? Thanks

XML Data

<?xml-stylesheet type="text/xsl" href="stylesheet.xsl"?>
<data>
    <object instance="197784" dataInstance="41" name="Give As You Earn Flex" itemNumber="1" pageNumber="1" pagesAvailable="1">
        <property id="{00fd4f20-8e9c-414f-b34f-2abd4a4dc3fe}" name="Effective Date">
            <format id="{332f8155-7253-4dc9-896c-61a3a3d19816}" answer="30/05/2014 13:39:55" />
        </property>
        <property id="{ea61f121-1c2b-47df-91af-3806eba65c4b}" name="Benefit Type ID">
            <format id="{05b7ea73-a86f-4119-b330-0a0f5a4e0143}" answer="GAYE" />
        </property>
        <object instance="197785" dataInstance="41" name="Default (GAYE)" itemNumber="1" pageNumber="1" pagesAvailable="1">
            <property id="{7f428c44-7800-4972-ad37-a005824c251f}" name="Flex Default Amount">
                <format id="{4cf95889-2249-4270-9ce0-9e2da5fedbb7}" answer="0" />
            </property>
            <property id="{cc70d36d-5700-41bf-9370-2ec34c6c7010}" name="Flex Default Cost">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
        </object>
        <object instance="197786" dataInstance="41" name="Model (GAYE)" itemNumber="1" pageNumber="1" pagesAvailable="1">
            <property id="{ea123f721-1c2b-47df-91af-3806eba65c4b}" name="Chosen Charity">
                <format id="{05b7ea73-a86f-4119-b330-0a0f5a4e0143}" answer="" />
            </property>
            <property id="{bf500440-3f1a-46ea-8937-1d8c4dfea274}" name="Flex Model Amount">
                <format id="{4cf95889-2249-4270-9ce0-9e2da5fedbb7}" answer="0" />
            </property>
            <property id="{bf9af022-ba8b-46ed-b043-573c01ba2e1d}" name="Flex Model Cost">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
            <property id="{2d94fe41-8492-4c5d-945a-a23bb5dfcf93}" name="Amount Liable for Tax">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
            <property id="{8555974b-b80e-4704-9241-867cbb435523}" name="Amount Liable for NI">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
        </object>
        <object instance="197787" dataInstance="41" name="Requested (GAYE)" itemNumber="1" pageNumber="1" pagesAvailable="1">
            <property id="{0a113492-faed-4c6e-be73-d6c14210f0b3}" name="Flex Requested Amount">
                <format id="{4cf95889-2249-4270-9ce0-9e2da5fedbb7}" answer="0" />
            </property>
            <property id="{28db97f2-9346-498d-b0b7-724535af30c4}" name="Flex Requested Cost">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
        </object>
        <object instance="197788" dataInstance="41" name="Current (GAYE)" itemNumber="1" pageNumber="1" pagesAvailable="1">
            <property id="{b0424854-bbf4-4299-080e-2480e6c09172}" name="Flex Current Amount">
                <format id="{4cf95889-2249-4270-9ce0-9e2da5fedbb7}" answer="0" />
            </property>
            <property id="{2cb5ac07-a5c7-4bfd-9b15-925a6dd5ba6c}" name="Flex Current Discount Amount">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
            <property id="{b8a7f2fe-9590-44ca-bc3d-027c76ff3dff}" name="Flex Current Value">
                <format id="{05b7ea73-a86f-4119-b330-0a0f5a4e0143}" answer="0" />
            </property>
            <property id="{e133d446-443a-419e-812f-f6506f0101db}" name="Flex Current VAT Amount">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
            <property id="{16d1795a-ad48-401e-9dc4-68f76310e238}" name="Flex Current Cost">
                <format id="{c7cf6728-47b3-4851-9633-f689b5391e88}" answer="0.0000" indicator="GBP" />
            </property>
        </object>
        <Object_ID ObjectName="Give As You Earn Flex" ParentDataInstance="47" ParentObjectInstance="197759" EmployeeObjectInstance="197993" EmployeeDataInstance="47" />
        <ChildObject_ID ChildObjectName="Default (GAYE)" ChildObjectInstance="197785" />
        <ChildObject_ID ChildObjectName="Model (GAYE)" ChildObjectInstance="197786" />
        <ChildObject_ID ChildObjectName="Requested (GAYE)" ChildObjectInstance="197787" />
        <ChildObject_ID ChildObjectName="Current (GAYE)" ChildObjectInstance="197788" />
    </object>
    <variables>
        <variable type="request.querystring" name="DP" value="47:197738/47:197759/41:197784" />
        <variable type="request.querystring" name="select" value="true" />
        <variable type="ID" name="UserRole" value="Employee" />
        <variable type="date" fulldate="14/08/2014 10:17:13" ukdate="14 August 2014" shortdate="14/08/2014" year="2014" month="8" monthname="August" day="14" timeGMT="14/08/2014 09:17:13" time="14/08/2014 10:17:13" />
    </variables>
    <options mode="Any Value" type="CoverLevel" inputName="Flex Model Amount|197786|41" modelValue="0" modelAdditionalValue="" currentValue="0" currentAdditionalValue="" formatting="Currency" suffix="Donation" minimum="1" maximum="11666.67" increment="0.01" charityName="">
        <selectionText>Please select the amount that you would like to donate per pay period:</selectionText>
        <additionalSelectionText />
        <onChange>
            validateDependants('',this.value,'No');toggleDeclarationBox(this.value)
        </onChange>
        <option value="0" location="0" cost="00" alias="No Donation" validation="No Cover" />
    </options>
</data>

XSLT stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>testing</h2>
     <xsl:for-each select="data">
      <xsl:value-of select="name"/>
        <xsl:value-of select="property"/>
        <xsl:value-of select="format"/>
      </xsl:for-each>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

原文:https://stackoverflow.com/questions/32418785
更新时间:2023-01-03 09:01

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)