Jak wybrać dwa atrybuty z tego samego węzła z jednym wyrażeniem w XPath?
Na przykład:
//person[@id='abc123']/@haircolor|/@weight"
PS. istnieje wiele rekordów "person"
33
Author: Ciro Santilli 新疆改造中心 六四事件 法轮功, 2011-05-17
4 answers
Spróbuj tego:
//person[@id='abc123']/@*[name()='weight' or name()='haircolor']
Jeśli używasz procesora XPath 2.0, Możesz również użyć opcji ładniejszej:
//person[@id='abc123']/(@haircolor|@weight)`
54
Author: Kobi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-05-17 11:47:20
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-05-17 11:47:20
Czy chcesz wyszukiwać węzły osób na podstawie wartości wielu atrybutów. Jeśli to jest pytanie, to możesz po prostu użyć ands np.
//person[@id='abc123' and @haircolor='blue' and @weight='...']
Jeśli chcesz wyszukać jeden atrybut, ale zwróć wartości innych atrybutów, zrobiłbym coś takiego:
<xsl:template match="person[@id='abc123']">
<xsl:value-of select="@haircolor"/>
<xsl:value-of select="@weight"/>
</xsl:template>
23
Author: planetjones,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-05-17 10:21:35
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-05-17 10:21:35
Jeśli próbujesz uzyskać wartości określonych atrybutów, sugerowałbym wprowadzenie zmiennej dla żądanej osoby.
<xsl:variable name="person" select="//person[@id = 'abc123']" />
Następnie możesz uzyskać dowolny atrybut od żądanej osoby za pomocą podanej zmiennej.
<xsl:value-of select="$person/@haircolor" />
<xsl:value-of select="$person/@weight" />
2
Author: Osiris76,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-05-17 10:15:52
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-05-17 10:15:52
Przykładowy XML:
<X>
<Y ATTRIB1=attrib1_value ATTRIB2=attrib2_value/>
</X>
string xPath="/" + X + "/" + Y +
"[@" + ATTRIB1 + "='" + attrib1_value + "']" +
"[@" + ATTRIB2 + "='" + attrib2_value + "']"
XPath Testbed: http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm
0
Author: Manjesh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-05 05:53:06
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-05 05:53:06