Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates xslt模板-如何传入属性及其值?_Templates_Xslt - Fatal编程技术网

Templates xslt模板-如何传入属性及其值?

Templates xslt模板-如何传入属性及其值?,templates,xslt,Templates,Xslt,我正在使用一些XML,其中节点有很多属性,我正在使用XSL创建一个FO PDF文件(报告)。我正在尝试创建一个模板,该模板在当前节点上具有特定属性,并创建一个具有一些基本格式的fo:block 下面是一个模板,它创建了一个节点上所有属性和值的大列表 XSL: 但是,有时我只想获取其中一个或两个属性,而不是所有属性。我猜这是很明显的事情,但由于我缺乏经验,我还没有弄明白 我正在尝试进行相同的格式化,但我似乎无法正确地获得语法,以便能够将我的值传递给参数,并获得我想要的。以下是我所拥有的: XS

我正在使用一些XML,其中节点有很多属性,我正在使用XSL创建一个FO PDF文件(报告)。我正在尝试创建一个模板,该模板在当前节点上具有特定属性,并创建一个具有一些基本格式的
fo:block

下面是一个模板,它创建了一个节点上所有属性和值的大列表

XSL:


但是,有时我只想获取其中一个或两个属性,而不是所有属性。我猜这是很明显的事情,但由于我缺乏经验,我还没有弄明白

我正在尝试进行相同的格式化,但我似乎无法正确地获得语法,以便能够将我的值传递给参数,并获得我想要的。以下是我所拥有的:

XSL:


以下是我试图称之为: XSL:


我的XML如下所示:

<DevicePatientEncounter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                        GeneratedTime="2011-12-14T13:36:05" 
                        EncounterDate="2011-11-15T11:04:54" 
                        xmlns="device">
    <Encounter>
        <Followup UnderlyingRhythm="Sinus bradycardia" 
                  UnderlyingRhythmRateBpm="44" 
                  IsPmDependent="false" 
                  PresentingRhythm="Atrial fibrillation" 
                  BatteryChargeSeconds="5" 
                  AutoCapFrequency="3 Years" 
                  LastCapacitorFormDate="2011-10-25T00:00:00" 
                  BatteryLongevity="0" 
                  BatteryVoltage="11" 
                  BatteryStatus="MOL"/>
    </Encounter>
</DevicePatientEncounter>
<xsl:template name="createAttributeValuePair">
    <xsl:param name="attribute" select="."/>
    <fo:block>
        <xsl:value-of select="concat(name($attribute),':   ')"/>
        <xsl:value-of select="$attribute"/>
    </fo:block>
</xsl:template>

一些注意事项:

  • 您正在将属性传递给
    createAttributeValuePair
    ,但从未对参数执行任何操作
  • 您在该模板中循环使用
    @*
    ,但该模板似乎是为输出单个属性的名称和值而设计的
  • 此外,
    calltemplate
    不会更改当前节点,因此不清楚循环中迭代了哪些元素的属性
我猜你在找这样的东西:

<DevicePatientEncounter xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                        GeneratedTime="2011-12-14T13:36:05" 
                        EncounterDate="2011-11-15T11:04:54" 
                        xmlns="device">
    <Encounter>
        <Followup UnderlyingRhythm="Sinus bradycardia" 
                  UnderlyingRhythmRateBpm="44" 
                  IsPmDependent="false" 
                  PresentingRhythm="Atrial fibrillation" 
                  BatteryChargeSeconds="5" 
                  AutoCapFrequency="3 Years" 
                  LastCapacitorFormDate="2011-10-25T00:00:00" 
                  BatteryLongevity="0" 
                  BatteryVoltage="11" 
                  BatteryStatus="MOL"/>
    </Encounter>
</DevicePatientEncounter>
<xsl:template name="createAttributeValuePair">
    <xsl:param name="attribute" select="."/>
    <fo:block>
        <xsl:value-of select="concat(name($attribute),':   ')"/>
        <xsl:value-of select="$attribute"/>
    </fo:block>
</xsl:template>

下面是一个完整的演示:

<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:fo="http://www.w3.org/1999/XSL/Format" 
                xmlns:device="device">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="/">
        <fo:block font-weight="normal" margin-left="6pt">
            <xsl:call-template name="createAttributeValuePair">
                <xsl:with-param name="attribute" 
                      select="/device:DevicePatientEncounter/device:Encounter/
                                  device:Followup/@UnderlyingRhythm"/>
            </xsl:call-template>
        </fo:block>
    </xsl:template>
    <xsl:template name="createAttributeValuePair">
        <xsl:param name="attribute" select="."/>
        <fo:block>
            <xsl:value-of select="concat(name($attribute),':   ')"/>
            <xsl:value-of select="$attribute"/>
        </fo:block>
    </xsl:template>
</xsl:stylesheet>

给出示例XML时,将生成以下输出:

<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:device="device"
          font-weight="normal"
          margin-left="6pt">
   <fo:block>UnderlyingRhythm:   Sinus bradycardia</fo:block>
</fo:block>

潜在心律:窦性心动过缓
<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:device="device"
          font-weight="normal"
          margin-left="6pt">
   <fo:block>UnderlyingRhythm:   Sinus bradycardia</fo:block>
</fo:block>