使用xslt

时间:2015-09-09 10:51:31

标签: html xml xslt

我有这个xml

<?xml version="1.0" encoding="UTF-8"?>
......
  <itemBody>
    <div class="grid-row">
      <div class="col-12">
        <associateInteraction shuffle="false" maxAssociations="0" minAssociations="0" responseIdentifier="RESPONSE">
          <prompt/>
          <simpleAssociableChoice fixed="false" showHide="show" matchMax="0" matchMin="0" identifier="choice_1">Bolbasoor<img src="001.png" alt="001" width="100%"/></simpleAssociableChoice>
          <simpleAssociableChoice fixed="false" showHide="show" matchMax="0" matchMin="0" identifier="choice_2">Pikachu<img src="Pikachu-the-ultimate-pokemon-fan-club-11690553-450-413.jpg" alt="Pikachu the-ultimate-pokemon-fan-club-11690553-450-413" width="100%"/></simpleAssociableChoice>
          <simpleAssociableChoice fixed="false" showHide="show" matchMax="0" matchMin="0" identifier="choice_3">Squeroo<img src="007.png" alt="007" width="100%"/></simpleAssociableChoice>
          <simpleAssociableChoice fixed="false" showHide="show" matchMax="0" matchMin="0" identifier="choice_4">Chalmender<img src="2438704-1202149925_t.png" alt="2438704 1202149925_t" width="100%"/></simpleAssociableChoice>
        </associateInteraction>
      </div>
    </div>
  </itemBody>
......

我需要提取每个简单的可关联选择(标识符,文本和源图像) 像这样:

<param name="hotspot0" value="choice_1::Bolbasoor::001.png"> 

所以我使用XSLT提取标识符和文本,但我无法提取源图像。我怎么能这样做?

<xsl:variable name="choices" as="element(qti:simpleAssociableChoice)*" select="qw:filter-visible(qti:simpleAssociableChoice)"/>
<param name="hotspot_count" value="{count($choices)}"/>
<xsl:for-each select="$choices">
    <xsl:variable name="content" as="node()*">
       <xsl:apply-templates/>
    </xsl:variable>
    <param name="hotspot{position()-1}" value="{@identifier}::{$content}::Here I need to source image"/>
</xsl:for-each>

1 个答案:

答案 0 :(得分:1)

源图像是src元素的img属性,它是simpleAssociableChoice的子元素,因此我认为您想要的表达式是img/@src

<param name="hotspot{position()-1}" value="{@identifier}::{$content}::{img/@src}"/>

如果您的实际XML具有命名空间,那么它可能应该是qti:img/@src

<param name="hotspot{position()-1}" value="{@identifier}::{$content}::{qti:img/@src}"/>