XSL question for a newbie

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • unimax
    New Member
    • Sep 2008
    • 3

    XSL question for a newbie

    I am just learning XSL to read from XML. How to read this xml please? I just cannot make to work though it looks simple. Thanks a bunch.


    <?xml version="1.0" encoding="ASCII "?>
    <?xml-stylesheet href="paramspec .xsl" type="text/xsl" ?>
    <lm:Component xmi:version="2. 0" xmlns:xmi="http ://www.omg.org/XMI" xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" xmlns:lm="http:///com.ti.ipmeta.e core" name="mcasp" description="Mu lti-channel Audio Serial Port" ipstatus="Devel opment" ipcategory="Log ic" ipfunction="Oth erCommunication s" memory="true" configurable="t rue">
    </lm:Component>

    And this my XSL sheet below
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform" xmlns:xdb="http ://xmlns.oracle.co m/xdb" xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">

    <xsl:template match="/">
    <html>
    <head>
    <title>IP Meta Status</title>
    </head>
    <body>
    <h2>Name :</h2>
    <xsl:for-each select="Compone nt/name">
    <xsl:apply-templates select="name"/>
    </xsl:for-each>
    </body>
    </html>
    </xsl:template>
    <xsl:template match="name">
    <div style="font-family:Verdana, Arial; font-size:18pt; font- weight:bold">
    <xsl:value-of select="."/>
    </div>
    </xsl:template>
    </xsl:stylesheet>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    XSL question for a newbie

    to put it in simple words: this is a case of overkill.

    (you could go for latin-1 or utf-8 charset as well)
    btw. you only have one element defined...

    the xsl cannot access the xml document tree, because the xml's namespace is missing, "name" is an attribute not an element (and therefore there is only one).

    this should get you started:
    [CODE=xml]<?xml version="1.0" encoding="UTF-8" ?>
    <xsl:styleshe et
    version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    xmlns:xdb="http ://xmlns.oracle.co m/xdb"
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xmlns:xmi="http ://www.omg.org/XMI"
    xmlns:lm="http:///com.ti.ipmeta.e core">

    <xsl:template match="/">
    <html>
    <head>
    <title>IP Meta Status</title>
    </head>
    <body>
    <h2>Name :</h2>
    <div style="font-family:Verdana, Arial; font-size:18pt; font- weight:bold">
    <xsl:value-of select="/lm:Component/@name"/>
    </div>
    </body>
    </html>
    </xsl:template>

    </xsl:stylesheet>[/CODE]
    regards

    Comment

    • unimax
      New Member
      • Sep 2008
      • 3

      #3
      That works. Adding the namespace and other suggested changed resolved it. I got confused with attribute and element. Thanks.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        XSL question for a newbie

        I'm glad I could help

        Comment

        • unimax
          New Member
          • Sep 2008
          • 3

          #5
          Is there a way I could loop thro' each of the attributes instead of processing each one by their name? Thanks.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            yes. how exactly you do it depends on the wanted output
            [CODE=xml]// you can copy attributes
            <xsl:template match="node()">
            <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
            </xsl:copy>
            </xsl:template>

            // or get them in a for-each loop
            <xsl:for-each select="@*">
            // use your code here
            <xsl:value-of select="."/>
            </xsl:for-each>[/CODE]
            regards

            Comment

            Working...