2016-08-04 74 views
-2

因此我们在考虑了一个xPath错误后,经过了几个小时的考试(我失败了),这是我来这里寻求帮助的。XML,可能是我找不到的简单错误(考试XML)

<!-- TODO customize transformation rules 
    syntax recommendation http://www.w3.org/TR/xslt 
--> 
<xsl:template match="/"> 
    <html> 
     <head> 
      <link rel="stylesheet" type="text/css" href="StylesheetWorkoutWimVanoverwalle.css" /> 
      <title>Workouts by Wim Van Overwalle and friends</title> 
     </head> 
     <body> 
      <h1>Workouts by Wim Van Overwalle and Friends</h1> 
      <p>Total Number of workouts By Wim Van Overwalle</p> 
      <div> 
      <xsl:value-of select ="sum(workout)"/> 
      <xsl:for-each select="workouts/workout/@type='running'"> 
       <xsl:sort select="workout/starttime" 
          order = "ascending" 
          data-type="number"/> 
       <xsl:value-of select = "naam"/> 
       <xsl:value-of select="distance/@km"/> 
       <xsl:value-of select="starttime/@date"/> 
       <xsl:value-of select="location/@country"/> 
       <xsl:value-of select="distance/@km"/> 
       <xsl:value-of select="duration"/>          
      </xsl:for-each> 
      </div> 
      <xsl:for-each select="workouts/workout[@type='cycling']"> 
       <xsl:value-of select = "naam"/> 
       <xsl:value-of select="distance/@km"/> 
       <xsl:value-of select="starttime/@date"/> 
       <xsl:value-of select="location/@country"/> 
       <xsl:value-of select="distance/@km"/> 
       <xsl:value-of select="duration"/>          
      </xsl:for-each> 
      <xsl:for-each select="workouts/workout[@type='running']"> 
        <xsl:value-of select = "naam"/> 
       <xsl:value-of select="distance/@km"/> 
       <xsl:value-of select="starttime/@date"/> 
       <xsl:value-of select="location/@country"/> 
       <xsl:value-of select="distance/@km"/> 
       <xsl:value-of select="duration"/> 
      </xsl:for-each> 
     </body> 
    </html> 
</xsl:template> 

^XSL文件

<xs:schema version="1.0" 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     elementFormDefault="qualified"> 
<xs:element name = "workouts"> 
    <xs:complexType> 
     <xs:sequence> 
      <xs:element ref= "workout" 
         minOccurs="1" 
         maxOccurs="unbounded"/> 
     </xs:sequence> 
    </xs:complexType> 
</xs:element> 
<xs:element name= "workout"> 
    <xs:complexType> 
     <xs:sequence> 
      <xs:element name = "person"/> 
      <xs:element name = "starttime" type="xs:dateTime"/> 
      <xs:element name = "distance" type="xs:decimal"/> 
      <xs:element name= "duration" type="xs:time"/> 
      <xs:element name="avgpace" type="xs:time"/> 
      <xs:element name = "location"> 
       <xs:complexType> 
       <xs:attribute name="country"> 
        <xs:simpleType> 
         <xs:restriction base= "xs:string"> 
          <xs:pattern value="[A-Z][A-Z]"/> 
         </xs:restriction> 
        </xs:simpleType> 
       </xs:attribute> 
       </xs:complexType> 
      </xs:element> 
     </xs:sequence> 
     <xs:attribute name= "type"> 
      <xs:simpleType> 
       <xs:restriction base="xs:string"> 
        <xs:enumeration value='running'/> 
        <xs:enumeration value='cycling'/> 
        <xs:enumeration value='walking'/> 
       </xs:restriction> 
      </xs:simpleType> 
     </xs:attribute> 
    </xs:complexType> 
</xs:element> 

^XSD网络乐

workouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="WorkoutsWimVanoverWalle.xsd"> 
    <workout type="running"> 
     <person>Wim Van Overwalle</person> 
     <starttime>2016-05-11T07:36:00</starttime> 
     <distance unit="km">6.09</distance> 
     <duration>00:36:50</duration> 
     <avgpace>00:05:52</avgpace> 
     <location country="BE">Kortrijk</location> 
    </workout> 

^我的XML文件

得到的一个错误,说的一部分:“XSLT的转型过程中的错误:一个节点集,预计为XPath的表达式的结果”,请说明:/

+0

我越来越而XSTL改造是一个节点集去的errpr预期为XPath的表达式的结果 –

+1

不要道歉对于太长和太宽的问题,然后让它太长而太宽泛。 **修复它。** – kjhughes

+0

好吧,我只是想为xPath问题得到解决,因为我找不到它。就像我一直在尝试3小时的东西找不到任何东西:/ –

回答

0

当我运行xsltproc,我得到了以下错误消息:

runtime error: file foo.xsl line 17 element for-each 
The 'select' expression does not evaluate to a node set. 

有问题的路线是:

<xsl:for-each select="workouts/workout/@type='running'"> 

也许你的意思是不是这样说:

<xsl:for-each select="workouts/workout[@type='running']"> 
+0

嗯这是一个错误,谢谢,但仍然得到xPath错误 –

+0

修复该错误后,您的代码完全适合我。请编辑您的帖子以包含实际示例代码(缩短您的内容并使其完整并可运行)以及如何重新创建问题的说明。 –