0
如果文本包含<vehicleType>
和<color>
中的任何單詞,我正試圖獲取<line>
中的文本。我還需要計算<description>
中包含的<vehicleType>
和<color>
中有多少個單詞。是否有可能使用XSL(版本= 1.0)?XSL:獲取單獨節點中包含任何單詞的文本值
輸出應看起來像:
Vehicle type (4)
This vehicle is a white <font color="red">compact car</font>.
This vehicle is a orange <font color="red">minivan</font>.
This vehicle is a red <font color="red">sedan</font>.
This vehicle is a yellow <font color="red">truck</font>.
Color (4)
This vehicle is a <font color="red">white</font> compact car.
This vehicle is a <font color="red">red</font> sedan.
This vehicle is a <font color="red">yellow</font> truck.
This vehicle is a <font color="red">yellow</font> crossover.
這裏是簡化的XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test9.xsl"?>
<items>
<vehicleTypes>
<vehicleType>truck</vehicleType>
<vehicleType>compace</vehicleType>
<vehicleType>car</vehicleType>
<vehicleType>sedan</vehicleType>
<vehicleType>minivan</vehicleType>
</vehicleTypes>
<colors>
<color>red</color>
<color>yellow</color>
<color>blue</color>
<color>white</color>
<color>purple</color>
<color>gold</color>
<color>silver</color>
</colors>
<item>
<description>
<p>
<line>
This vehicle is a white compact car.
</line>
<line>
This vehicle is a orange minivan.
</line>
<line>
This vehicle is a red sedan.
</line>
<line>
This vehicle is a yellow truck.
</line>
<line>
This vehicle is a yellow crossover.
</line>
</p>
</description>
</item>
</items>
謝謝@ Sperberg-McQueen。我確實擁有對XML的控制權,並按照您的建議更改了「vehecleType」和「color」(見上文)。但是,我無法讓它工作。我是XSL新手,你會介意發佈整個xsl嗎?我非常感謝你的幫助! –
其實,是的,我會介意的。沒有冒犯性,但我在這個和其他大多數答案中的目標是向提問者展示如何幫助自己並幫助他們瞭解他們可能想要了解的主題以解決他們的問題。我避免提交完整的解決方案,因爲它們在幫助提問者學習方面效果不佳。 –
我明白。謝謝你的幫助。 –