ORIGINAL - 這是我原來的XML:XML到XML(短版本)與XSL
<course acad_year="2012" cat_num="85749" offered="N" next_year_offered="2013">
<term term_pattern_code="4" fall_term="Y" spring_term="Y">full year</term>
<department code="VES">
<dept_long_name>Department of Visual and Environmental Studies</dept_long_name>
<dept_short_name>Visual and Environmental Studies</dept_short_name>
</department>
</course>
期望的結果 - 我想創建原始XML的另一種較短的版本,這將使組列出所有部門代碼就像下面的例子:
<departments>
<department code="some_code" name="some_name"/>
<department code="some_code" name="some_name"/>
<department code="some_code" name="some_name"/>
</departments>
這就是我想和不工作:
<xsl:template match="/">
<departments>
<xsl:for-each-group select="fas_courses/course" group-by="department[@code]">
<xsl:text disable-output-escaping="yes"> <department code=" </xsl:text>
<xsl:value-of select="department/@code"/>
<xsl:text>" name="</xsl:text>
<xsl:value-of select="dept_short_name"/>
<xsl:text disable-output-escaping="yes">"><department/></xsl:text>
</xsl:for-each-group>
</departments>
</xsl:template>
我正在 F [撒克遜-PE 9.4.0.3]的屬性「代碼」與元素類型「部門」相關聯的值必須不包含在「<」字符的錯誤。
從錯誤信息中,我明白'<'字符給了我xsl:text元素內部的一個錯誤,但是如何將這個字符放在那裏?,我已經在使用disable-output-escaping =「是的「,還有什麼? 謝謝!
在提供的XML文檔中沒有名爲'fas_courses'的元素 - 它顯然不需要任何分組。請編輯該問題,並提供一份具有代表性的XML文檔以及此文檔的確切結果。學會發布完整且無誤導性的問題。 -1 –
Flynn的答案是正確的,但如果出於某種原因未來您確實需要插入'<',那麼需要將其轉義爲'<' – nine9ths