0

我是 Xpath 的初学者,但我有一个简单的问题。

我正在查询这个文件

<?xml version="1.0" encoding="UTF-8"?>
<MC>
  <SC>
    <S uid="721" gen="" yr="2000" art="The Band" cmp="Robbie Robertson" fld="/mnt/sdcard/Music/The Band/The Band" alb="The Band" ttl="Up On Cripple Creek (2000 Digital Remaster)"/>
    <S uid="722" gen="" yr="2003" art="The Band" cmp="Robbie Robertson" fld="/mnt/sdcard/Music/The Band/Greatest Hits" alb="Greatest Hits" ttl="The Weight (2000 Digital Remaster)"/>
    <S uid="723" gen="" yr="2005" art="The Cascades" cmp="John Gummoe" fld="/mnt/sdcard/Music/The Cascades/Rhythm Of The Rain" alb="Rhythm Of The Rain" ttl="Rhythm Of The Rain (LP Version)"/>
    <S uid="724" gen="" yr="1976" art="Creedence Clearwater Revival" cmp="John Fogerty" fld="/mnt/sdcard/Music/Creedence Clearwater Revival/Chronicle Volume One" alb="Chronicle Volume One" ttl="Who'll Stop the Rain"/>
    <S uid="725" gen="" yr="2001" art="Johnny Cash" cmp="Johnny Cash" fld="/mnt/sdcard/Music/Johnny Cash/The Complete Sun Singles, vol. 1" alb="The Complete Sun Singles, vol. 1" ttl="I Walk the Line"/>
    <S uid="762" gen="" yr="1980" art="Bob Seger" cmp="Bob Seger" fld="/mnt/sdcard/Music/Bob Seger &amp; the Silver Bullet Band/Greatest Hits" alb="Greatest Hits" ttl="Against The Wind"/>
    <S uid="763" gen="" yr="1975" art="The Eagles" cmp="G. Frey" fld="/mnt/sdcard/Music/The Eagles/Their Greatest Hits" alb="Their Greatest Hits" ttl="Lyin' Eyes"/>
    <S uid="764" gen="" yr="1987" art="Johnny Horton" cmp="M. Phillips" fld="/mnt/sdcard/Music/Johnny Horton/Johnny Horton's Greatest Hits" alb="Johnny Horton's Greatest Hits" ttl="North To Alaska"/>
    <S uid="765" gen="" yr="1969" art="Marty Robbins" cmp="&lt;unknown&gt;" fld="/mnt/sdcard/Music/Marty Robbins/Super Hits" alb="Super Hits" ttl="You Gave Me A Mountain"/>
    <S uid="792" gen="" yr="1976" art="Bob Seger" cmp="Bob Seger" fld="/mnt/sdcard/Music/Bob Seger &amp; the Silver Bullet Band/Greatest Hits" alb="Greatest Hits" ttl="Night Moves"/>
    <S uid="793" gen="" yr="2003" art="Conway Twitty" cmp="Conway Twitty/Jack Nance" fld="/mnt/sdcard/Music/Conway Twitty/Hello Darlin' 15 #1 Hits" alb="Hello Darlin' 15 #1 Hits" ttl="It's Only Make Believe"/>
    <S uid="794" gen="" yr="1996" art="Kenny Rogers &amp; The First Edition" cmp="Mel Tillis" fld="/mnt/sdcard/Music/Kenny Rogers &amp; the First Edition/Anthology" alb="Anthology" ttl="Ruby, Don't Take Your Love To Town"/>
    <S uid="795" gen="" yr="2004" art="Neil Young" cmp="Neil Young" fld="/mnt/sdcard/Music/Neil Young/Greatest Hits" alb="Greatest Hits" ttl="Old Man"/>
    <S uid="796" gen="" yr="2009" art="Neil Young" cmp="Neil Young" fld="/mnt/sdcard/Music/Neil Young/Harvest" alb="Harvest" ttl="Heart Of Gold"/>
    <S uid="797" gen="" yr="2011" art="The Springfields" cmp="Dick Reynolds/Jack Rhodes" fld="/mnt/sdcard/Music/The Springfields/The Very Best Of" alb="The Very Best Of" ttl="Silver Threads And Golden Needles"/>
    <S uid="798" gen="" yr="1987" art="The Statler Brothers" cmp="Don Reid" fld="/mnt/sdcard/Music/The Statler Brothers/The Best Of The Statler Brothers" alb="The Best Of The Statler Brothers" ttl="Susan When She Tried"/>
    <S uid="799" gen="" yr="2005" art="The Statler Brothers" cmp="Don Reid" fld="/mnt/sdcard/Music/The Statler Brothers/The Definitive Collection" alb="The Definitive Collection" ttl="The Class Of '57"/>
    <S uid="800" gen="" yr="2005" art="The Statler Brothers" cmp="Don Reid" fld="/mnt/sdcard/Music/The Statler Brothers/The Definitive Collection" alb="The Definitive Collection" ttl="I'll Go To My Grave Loving You"/>
    <S uid="801" gen="" yr="2006" art="Steve Miller Band" cmp="Steve Miller" fld="/mnt/sdcard/Music/Steve Miller Band/Greatest Hits  1974-1978" alb="Greatest Hits: 1974-1978" ttl="The Joker"/>
    <S uid="802" gen="" yr="2006" art="Steve Miller Band" cmp="Steve Miller" fld="/mnt/sdcard/Music/Steve Miller Band/Greatest Hits  1974-1978" alb="Greatest Hits: 1974-1978" ttl="Rock'n Me"/>
    <S uid="803" gen="" yr="2010" art="Gale Garnett" cmp="Gale Garnett" fld="/mnt/sdcard/Music/Various Artists/Early Girl 7  Hits" alb="Early Girl 7&quot; Hits" ttl="We'll Sing In The Sunshine"/>
    <S uid="804" gen="" yr="2004" art="Various Artists" cmp="Don Gibson" fld="/mnt/sdcard/Music/Various Artists/King of the Road" alb="King of the Road" ttl="I Can't Stop Loving You - Don Gibson"/>
    <S uid="805" gen="" yr="2005" art="Willie Nelson" cmp="Willie Nelson" fld="/mnt/sdcard/Music/Willie Nelson/America's Troubador" alb="America's Troubador" ttl="Angel Flying To Close To The Ground"/>
    <S uid="819" gen="" yr="1975" art="The Eagles" cmp="D. Henley" fld="/mnt/sdcard/Music/The Eagles/Their Greatest Hits" alb="Their Greatest Hits" ttl="Take It To The Limit"/>
    <S uid="820" gen="" yr="1973" art="The Eagles" cmp="Don Henley, Glen Frey" fld="/mnt/sdcard/Music/The Eagles/Their Greatest Hits" alb="Their Greatest Hits" ttl="Desperado"/>
    <S uid="821" gen="" yr="1985" art="The Highwaymen" cmp="Guy Clark" fld="/mnt/sdcard/Music/The Highwaymen/Highwayman" alb="Highwayman" ttl="Desperados Waiting For A Train"/>
    <S uid="832" gen="" yr="1970" art="Marty Robbins" cmp="&lt;unknown&gt;" fld="/mnt/sdcard/Music/Marty Robbins/Super Hits" alb="Super Hits" ttl="My Woman, My Woman, My Wife"/>
    <S uid="833" gen="" yr="1982" art="Marty Robbins" cmp="&lt;unknown&gt;" fld="/mnt/sdcard/Music/Marty Robbins/Super Hits" alb="Super Hits" ttl="Some Memories Just Won't Die"/>
    <S uid="834" gen="" yr="1985" art="The Highwaymen" cmp="Johnny Cash" fld="/mnt/sdcard/Music/The Highwaymen/Highwayman" alb="Highwayman" ttl="Committed To Parkview"/>
    <S uid="835" gen="" yr="1995" art="Roy Clark" cmp="Herbert Kretzmer, Charles Aznavour" fld="/mnt/sdcard/Music/Roy Clark/Greatest Hits - Roy Clark" alb="Greatest Hits - Roy Clark" ttl="Yesterday When I Was Young"/>
    <S uid="836" gen="" yr="1995" art="Roy Clark" cmp="Charlie Williams, Bobby George" fld="/mnt/sdcard/Music/Roy Clark/Greatest Hits - Roy Clark" alb="Greatest Hits - Roy Clark" ttl="I Never Picked Cotton"/>
    <S uid="842" gen="" yr="1970" art="Simon &amp; Garfunkel" cmp="Paul Simon" fld="/mnt/sdcard/Music/Simon &amp; Garfunkel/Simon &amp; Garfunkel's Greatest Hits" alb="Simon &amp; Garfunkel's Greatest Hits" ttl="Bridge Over Troubled Water [Live]"/>
    <S uid="843" gen="" yr="1977" art="The Oak Ridge Boys" cmp="&lt;unknown&gt;" fld="/mnt/sdcard/Music/The Oak Ridge Boys/Collection" alb="Collection" ttl="Y'all Come Back Saloon"/>
    <S uid="848" gen="" yr="1987" art="Vern Gosdin" cmp="Various" fld="/mnt/sdcard/Music/Vern Gosdin/Super Hits" alb="Super Hits" ttl="Chiseled In Stone"/>
    <S uid="849" gen="" yr="1987" art="Vern Gosdin" cmp="Various" fld="/mnt/sdcard/Music/Vern Gosdin/Super Hits" alb="Super Hits" ttl="Who You Gonna Blame It On This Time"/>
    <S uid="854" gen="" yr="1972" art="John Denver" cmp="&lt;unknown&gt;" fld="/mnt/sdcard/Music/John Denver/The Very Best Of John Denver [Disc 2]" alb="The Very Best Of John Denver [Disc 2]" ttl="Rocky Mountain High"/>
    <S uid="855" gen="" yr="1971" art="John Denver" cmp="&lt;unknown&gt;" fld="/mnt/sdcard/Music/John Denver/The Very Best Of John Denver [Disc 2]" alb="The Very Best Of John Denver [Disc 2]" ttl="Take Me Home, Country Roads"/>
    <S uid="856" gen="" yr="1995" art="Vince Gill" cmp="Vince Gill" fld="/mnt/sdcard/Music/Vince Gill/Souvenirs" alb="Souvenirs" ttl="Never Knew Lonely"/>
    <S uid="857" gen="" yr="1995" art="Vince Gill" cmp="Vince Gill - Tim Dubois" fld="/mnt/sdcard/Music/Vince Gill/Souvenirs" alb="Souvenirs" ttl="When I Call Your Name"/>
    <S uid="860" gen="" yr="1995" art="Vince Gill" cmp="Vince Gill - Brian Allsmiller" fld="/mnt/sdcard/Music/Vince Gill/Souvenirs" alb="Souvenirs" ttl="Pocket Full Of Gold"/>
    <S uid="863" gen="" yr="2000" art="Waylon Jennings" cmp="&lt;unknown&gt;" fld="/mnt/sdcard/Music/Waylon Jennings/Greatest Hits - Waylon Jennings" alb="Greatest Hits - Waylon Jennings" ttl="Bob Wills Is Still King"/>
    <S uid="864" gen="" yr="2000" art="Waylon Jennings" cmp="&lt;unknown&gt;" fld="/mnt/sdcard/Music/Waylon Jennings/Greatest Hits - Waylon Jennings" alb="Greatest Hits - Waylon Jennings" ttl="Just To Satisfy You"/>
  </SC>
  <PC>
    <P uid="504" ttl="Quick list"/>
    <P uid="867" ttl="My playlist 001"/>
  </PC>
</MC>

使用查询是/MC/SC/*/@yr,它输出属性@yr 的值列表。是否有一个 xpath 1.0 查询也会在结果的每个值旁边添加属性名称?

例如,

年份:2001 年份:2003 年份:2005

等等

4

1 回答 1

0

不,我认为这不能在 XPath 1.0 中完成。在 XPath 2.0 中这很容易;如果您坚持使用 XPath 1.0,我会使用宿主语言(即调用 XPath 处理器来评估表达式的程序)。

于 2013-03-29T18:02:42.427 回答