2016-08-04 162 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

修復該錯誤後,您的代碼完全適合我。請編輯您的帖子以包含實際示例代碼(縮短您的內容並使其完整並可運行)以及如何重新創建問題的說明。 –