Cristy
Cristy

Reputation: 557

xml to xml (shorter version) with XSL

ORIGINAL - this is my original XML:

<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>

DESIRED RESULT - I am trying to create another shorter version of the original XML that will group and list all department codes like in the example below:

   <departments>
      <department code="some_code" name="some_name"/>
      <department code="some_code" name="some_name"/>
      <department code="some_code" name="some_name"/>
   </departments>

This is what I am trying and not working:

   <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>

The error I am getting F [Saxon-PE 9.4.0.3] The value of attribute "code" associated with an element type "department" must not contain the '<' character.

From the error message, I understand the '<' character is giving me an error inside of the xsl:text element, but how do I put that character then?, I am already using disable-output-escaping="yes", is there anything else??? Thanks!

Upvotes: 1

Views: 107

Answers (2)

Flynn1179
Flynn1179

Reputation: 12075

Using disable-output-escaping is never a good idea, and you really don't need it here. Try this:

<xsl:template match="/">
  <departments>
    <xsl:for-each-group select="fas_courses/course" group-by="department/@code">
      <department code="{department/@code}" name="{department/dept_short_name}" />
    </xsl:for-each-group> 
  </departments>
</xsl:template>

Upvotes: 2

Alexis Wilke
Alexis Wilke

Reputation: 20770

You need to write your text inside <[DATA[...]]> so it doesn't get parsed or use < and > for the tags that you output.

Upvotes: 0

Related Questions