user
user

Reputation: 128

pass attribue values of tags of xml using xslt

I am new to xslt. I have following xml and xslt which i need to convert into html using XslCompiledTranform. I have following XML

<ref-list id="RL10">
 <label>
  <bold>7.0</bold>
 </label>
 <title>
  <bold>References</bold>
 </title>
  <ref id="R66" content-type="references">
   <label>2</label>
    <mixed-citation publication-type="book">
     <person-group person-group-type="author">
      <name>
       <surname>Chown,</surname>
       <given-names>Bill</given-names>
      </name>
     </person-group>, and
     <person-group person-group-type="author">
      <name>
       <surname>Lange</surname>
       <given-names>Michelle</given-names>
      </name>
     </person-group>. &#x201C;
     <source>Modernizing System Development: Requirements&#x002d;Based, Model&#x002d;Driven Design, Implementation and Test</source>.&#x201D;
     <publisher-name>Mentor Graphics Corp., ERTS</publisher-name>,
     <month>Feb.</month>
     <year>2012</year>.
    </mixed-citation></ref>
    <ref id="R67" content-type="references">
     <label>3</label>
      <mixed-citation publication-type="journal">
       <person-group person-group-type="author">
        <name>
         <surname>Blyler,</surname>
         <given-names>John</given-names>
        </name>
       </person-group>. &#x201C;
       <article-title>Model&#x002d;Driven Development Is Key to Low Power</article-title>.&#x201D; 
       <source>Chip Design Magazine &#x002d; JB&#x2019;s Circuit</source>,
       <month>Dec.</month>
       <day>6</day>,
       <year>2012</year>.
       <uri xlink:href="http://www.chipdesignmag.com/blyler/2012/12/06/model-driven-development-key-to-low-power/">http:&#x002F;&#x002F;www.chipdesignmag.com&#x002F;blyler&#x002F;2012&#x002F;12&#x002F;06&#x002F;model&#x002d;driven&#x002d;development&#x002d;key&#x002d;to&#x002d;low&#x002d;power&#x002F;</uri>.
      </mixed-citation>
     </ref>
 </ref-list>

I have the following xslt

<xsl:template match="ref-list/ref">
  <html>
   <head></head>
   <body>
    <xsl:apply-templates/>
   </body>
  </html>
</xsl:template>

<xsl:template match="ref-list/ref">
  <p>
    <xsl:value-of select="label"/>
    <xsl:for-each select="mixed-citation">
          <xsl:for-each select="person-group/name">
            <xsl:value-of select="given-names"/>
            <xsl:value-of select="surnames"/>
          </xsl:for-each>
      <xsl:text>,</xsl:text>
      <xsl:value-of select="source"/>
      <xsl:text>,</xsl:text>
      <xsl:value-of select="publisher-name"/>
      <xsl:text>,</xsl:text>
      <xsl:value-of select="day"/>
      <xsl:text>,</xsl:text>
      <xsl:value-of select="month"/>
      <xsl:text>,</xsl:text>
      <xsl:value-of select="year"/>
      <xsl:text>,</xsl:text>
      <xsl:for-each select="uri">
        <xsl:value-of select="."/>
      </xsl:for-each>
      <xsl:text>,</xsl:text>
      <xsl:value-of select="article-title"/>
      <xsl:text>,</xsl:text>
      <xsl:value-of select="publisher-loc"/>
      <xsl:text>,</xsl:text>
      <xsl:value-of select="volume"/>
      <xsl:text>,</xsl:text>
      <xsl:value-of select="issue"/>
    </xsl:for-each>
  </p>
</xsl:template>

I have to transform my xml to html using xslt. But while transforming, it is saying that 'xlink' is an undeclared prefix. I dont know how to parse it. I need the output that parse uri tag having xlink as its attribute.I dont know how to parse any attribute of the any xml tag. Can anyone please explain how to parse any xml tags having its attributes ?

Upvotes: 0

Views: 332

Answers (1)

Joel M. Lamsen
Joel M. Lamsen

Reputation: 7173

It is called a namespace. The root tag of your xml should contain

xmlns:xlink="http://www.w3.org/1999/xlink

If not it should be included everytime you add xlink:href in you tag.

Upvotes: 1

Related Questions