Question

I am trying to convert xml with xsd schema to xhtml.

so in my xml file, I have something like this:

<shf:BookShelf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="BookShelf BookShelf.xsd"
        xmlns:shf="BookShelf"
        xmlns:bk="BookType"
        xmlns:cmn="CommonType">
   <shf:Book Category="Physics">
      <bk:Name></bk:Name>
      <bk:Author>
         <cmn:FirstName></cmn:FirstName>
         <cmn:FamilyName></cmn:FamilyName>
      </bk:Author>
      <bk:Pages></bk:Pages>
      <bk:Language></bk:Language>
      <cmn:Source></cmn:Source>
   </shf:Book>
...
</shf:BookShelf>

I know it would be much easier to convert from merely xml to xhtml, but now I have <shf:Book> , how can refer to this entry in my xsl? This is what I did in my xsl, but it didn't work:

<xsl:for-each select="BookShelf/Book">
<tr>
  <td><xsl:value-of select="Name"/></td>     
</tr>
</xsl:for-each>
Was it helpful?

Solution

You can use:

<xsl:for-each select="shf:BookShelf/shf:Book">
    <tr>
         <td><xsl:value-of select="bk:Name"/></td>     
    </tr>
</xsl:for-each>

And declare the namespaces in your <xsl:stylesheet>:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
    xmlns:shf="BookShelf" xmlns:bk="BookType" xmlns:cmn="CommonType"> ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top