|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: some problems with my first XSL :( [namespace in
On Thu, 2005-07-21 at 18:17 +0200, Ana Yndurain wrote:
> OK! Thanks, it works!! I don't know how it could work before :S
>
> BUT now I have other "little" problem. It works when I use the namespace m in <xsl:template match="m:xxxx" ...> with direct attributes, but not when I use Xpath inside.
>
> For example, in next two templates "metricascomprobadas" & "listametricas" when I select @scope, or @description, it works fine. BUT when I try to count Values/Value, it doesn't work, or when I try to accede in
> <xsl:for-each select="Values/Value">, it doesn't work.
>
> I tried some options and any works.
>
> How have I to use de namespace inside a xsl:template??
George answered this question:
> Also you should change other references to elements from that
> namespace in XPath expressions if any to use the prefix.
I think what you're missing is that every element in your source
document is in the same namespace. So you should be specifying a
namespace for every element name in every xpath expression. In your
for-each mentioned above, you should use the expression:
select="m:Values/m:Value"
sdc
> Here are my 2 templates
>
> Thanks a lot!! You have made this day happier :D
>
> Ana
>
> ....
>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://metrics.sourceforge.net/2003/Metrics-First-Flat" >
>
> ....
>
> <!-- PLANTILLA METRICASCOMPROBADAS -->
> <!-- Parte del nodo Metrics (en /) y muestra la lista de metricas comprobadas -->
> <xsl:template match="m:Metrics" mode="metricascomprobadas">
> <h3>Metricas comprobadas en el proyecto <xsl:value-of select="translate(@scope,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/></h3>
> <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
> <tr>
> <th>Metrica</th>
> <th>Descripcion</th>
> <th>Archivos con valores fuera de rango</th>
> </tr>
> <xsl:for-each select="m:Metric">
> <!-- <xsl:sort select="count(Values/Value)" order="descending"/> -->
> <tr>
> <xsl:call-template name="alternated-row"></xsl:call-template>
> <!-- Enlace al listado de valores de la metrica correspondiente -->
> <td><a href="#f-{@id}"><xsl:value-of select="@id"/></a></td>
> <td><xsl:value-of select="@description"/></td>
> <td><xsl:value-of select="count(Values/Value)"/></td>
> </tr>
> </xsl:for-each>
> </table>
> </xsl:template>
>
> <!-- PLANTILLA LISTAMETRICAS -->
> <xsl:template match="m:Metric" mode="listametricas">
> <a name="f-{@id}"></a>
> <h3>Metrica <xsl:value-of select="@id"/> (<xsl:value-of select="@description"/>)</h3>
> <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
> <tr>
> <th>Archivo</th>
> <th>Valor</th>
> </tr>
> <xsl:for-each select="Values/Value">
> <tr>
> <xsl:call-template name="alternated-row"></xsl:call-template>
> <td><xsl:value-of select="@package"/><xsl:value-of select="@source"/></td>
> <td><xsl:value-of select="@value"/></td>
> </tr>
> </xsl:for-each>
> <xsl:for-each select="Value">
> <tr>
> <td>Total</td>
> <td><xsl:value-of select="@value"/></td>
> </tr>
> </xsl:for-each>
> </table>
> <a href="#top">Back to top</a>
> </xsl:template>
>
> -----Mensaje original-----
> De: George Cristian Bina [mailto:george@xxxxxxx]
> Enviado el: jueves, 21 de julio de 2005 16:21
> Para: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Asunto: Re: some problems with my first XSL :(
>
> Dear Ana,
>
> That looks like a complex task for the first XSL :).
> The problem is that you match on a Metrics element from no namespace
>
> <xsl:template match="Metrics" mode="cabecera">
>
> and your document contains a Metrics element from the
> http://metrics.sourceforge.net/2003/Metrics-First-Flat namespace
>
> <Metrics scope="p" type="Project" date="2005-07-20"
> xmlns="http://metrics.sourceforge.net/2003/Metrics-First-Flat">
>
> You need something like
> xmlns:m="http://metrics.sourceforge.net/2003/Metrics-First-Flat" in your
> stylesheet and then use
>
> <xsl:template match="m:Metrics" mode="cabecera">
>
> Also you should change other references to elements from that namespace
> in XPath expressions if any to use the prefix.
>
> Best Regards,
> George
> ---------------------------------------------------------------------
> George Cristian Bina
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> http://www.oxygenxml.com
>
>
> Ana Yndurain wrote:
> > Hi!
> > First, sorry about my english :S
> >
> > Ibm trying to do my first XSL to show some data from a XML created by Metrics 1.3.5
> > (a XML example of that XML and my XSL are at the end of the mail)
> >
> > My problem is that it only show Metrics/Cycle/Package values, and that is the only thing that I donbt want!!! b9
> >
> > Using oXygen program (debugger) I saw that the line <xsl:apply-templates mode="cabecera"/> doesnbt jump for that templateb& and I donbt know why.
> >
> > The strange thing is that my XSL was working perfectly, and suddenly it stoped b9
> >
> > Thanks for your help!!
> > Ana
> >
> > Now in Spanish :D
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > Hola!
> > Estoy haciendo un XSL para mostrar unos resultados que tengo en un xml (creado por el Metrics1.3.5) (os pongo el codigo de los dos abajo)
> >
> > Mi problema es que lo unico que me aparece es el contenido de Metrics/Cycle/Package, es decir, las xxx, que es justo lo C:nico que no quiero que salga :(
> >
> > Me he fijado que cuando llega a esta lC-nea (uso el debugger del editor oXygen)
> > <xsl:apply-templates mode="cabecera"/>
> > no salta a la plantilla cabecera, y no entiendo por que.
> >
> > Alguien tiene alguna idea?? Lo curioso es que ayer me funcionaba, y quedaba un html bastante chulo.
> > Le cambiC) el xml con el que estaba haciendo las pruebas, y no volviC3 a funcionar :(
> >
> > Os dejo debajo el formato del xml y el xsl que he creado.
> > Gracias!!
> >
> > Ana
> >
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > My XSL:
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > <?xml version="1.0" encoding="UTF-8"?>
> >
> > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> >
> > <!-- NODO RAIZ -->
> > <xsl:template match="/">
> > <html>
> > <!-- HOJA DE ESTILOS -->
> > <style type="text/css">
> > .bannercell {
> > border: 0px;
> > padding: 0px;
> > }
> > body {
> > margin-left: 10;
> > margin-right: 10;
> > font:normal 80% arial,helvetica,sanserif;
> > background-color:#FFFFFF;
> > color:#000000;
> > }
> > .a td {
> > background: #efefef;
> > }
> > .b td {
> > background: #fff;
> > }
> > th, td {
> > text-align: left;
> > vertical-align: top;
> > }
> > th {
> > font-weight:bold;
> > background: #ccc;
> > color: black;
> > }
> > table, th, td {
> > font-size:100%;
> > border: none
> > }
> > table.log tr td, tr th {
> >
> > }
> > h2 {
> > font-weight:bold;
> > font-size:140%;
> > margin-bottom: 5;
> > }
> > h3 {
> > font-size:100%;
> > font-weight:bold;
> > background: #525D76;
> > color: white;
> > text-decoration: none;
> > padding: 5px;
> > margin-right: 2px;
> > margin-left: 2px;
> > margin-bottom: 0;
> > }
> > </style>
> >
> > <head>
> > <title>
> > <!-- EJECUTA LA PLANTILLA CABECERA -->
> > <xsl:apply-templates mode="cabecera"/>
> >
> > </title>
> > </head>
> >
> > <body>
> > <a name="top"></a>
> >
> > <hr size="1" width="100%" align="left"/>
> >
> > <!-- EJECUTA LA PLANTILLA METRICASCOMPROBADAS -->
> > <xsl:apply-templates mode="metricascomprobadas"/>
> >
> > <hr size="1" width="100%" align="left"/>
> >
> > <!-- EJECUTA LA PLANTILLA LISTAMETRICAS -->
> > <xsl:apply-templates mode="listametricas"/>
> >
> > </body>
> > </html>
> > </xsl:template>
> >
> >
> > <!-- PLANTILLA CABECERA -->
> > <!-- Parte del nodo Metrics (en /) y muestra la cabecera con algunos datos -->
> > <xsl:template match="Metrics" mode="cabecera">
> > Metricas del proyecto: <xsl:value-of select="@scope"/>
> > </xsl:template>
> >
> >
> > <!-- PLANTILLA METRICASCOMPROBADAS -->
> > <!-- Parte del nodo Metrics (en /) y muestra la lista de metricas comprobadas -->
> > <xsl:template match="Metrics" mode="metricascomprobadas">
> > <h3>Metricas comprobadas en el proyecto <xsl:value-of select="translate(@scope,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/></h3>
> > <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
> > <tr>
> > <th>Metrica</th>
> > <th>Descripcion</th>
> > <th>Archivos con valores fuera de rango</th>
> > </tr>
> > <xsl:for-each select="Metric">
> > <xsl:sort select="count(Values/Value[@inrange='false'])" order="descending"/>
> > <tr>
> > <xsl:call-template name="alternated-row"></xsl:call-template>
> > <!-- Enlace al listado de valores de la metrica correspondiente -->
> > <td><a href="#f-{@id}"><xsl:value-of select="@id"/></a></td>
> > <td><xsl:value-of select="@description"/></td>
> > <td><xsl:value-of select="count(Values/Value[@inrange='false'])"/></td>
> > </tr>
> > </xsl:for-each>
> >
> > </table>
> > </xsl:template>
> >
> > <!-- PLANTILLA LISTAMETRICAS -->
> > <xsl:template match="Metric" mode="listametricas">
> > <a name="f-{@id}"></a>
> > <h3>Metrica <xsl:value-of select="@id"/> (<xsl:value-of select="@description"/>)</h3>
> > <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
> > <tr>
> > <th>Archivo</th>
> > <th>Valor</th>
> > </tr>
> >
> > <xsl:for-each select="Values/Value[@inrange='false']">
> > <tr>
> > <xsl:call-template name="alternated-row"></xsl:call-template>
> > <td><xsl:value-of select="@package"/><xsl:value-of select="@source"/></td>
> > <td><xsl:value-of select="@value"/></td>
> > </tr>
> > </xsl:for-each>
> >
> > <xsl:for-each select="Value">
> > <tr>
> > <td>Total</td>
> > <td><xsl:value-of select="@value"/></td>
> > </tr>
> > </xsl:for-each>
> >
> > </table>
> > <a href="#top">Back to top</a>
> > </xsl:template>
> >
> > <!-- PLANTILLA QUE PONE CADA FILA DE LA TABLA DE UN COLOR -->
> > <xsl:template name="alternated-row">
> > <xsl:attribute name="class">
> > <xsl:if test="position() mod 2 = 1">a</xsl:if>
> > <xsl:if test="position() mod 2 = 0">b</xsl:if>
> > </xsl:attribute>
> > </xsl:template>
> >
> > </xsl:stylesheet>
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > My XML
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > <?xml version="1.0" encoding="UTF-8"?>
> > <Metrics scope="p" type="Project" date="2005-07-20" xmlns="http://metrics.sourceforge.net/2003/Metrics-First-Flat">
> > <Cycle name="es.m.p.bu.vo et al" nodes="4" diameter="3">
> > <Package>es.m.p.bu.vo</Package>
> > <Package>es.m.p.ws</Package>
> > <Package>es.m.p.bu.ma</Package>
> > <Package>es.m.p.bu.ex</Package>
> > </Cycle>
> > <Cycle name="es.pr.m.p.ma et al" nodes="3" diameter="2">
> > <Package>es.m.p.ma</Package>
> > <Package>es.m.p.ma.tr</Package>
> > <Package>es.m.p.ma.psp</Package>
> > </Cycle>
> > <Metric id = "NSM" description ="Number of Static Methods">
> > <Values per = "type" total = "20" avg = "0,278" stddev = "0,961" max = "7">
> > <Value name="aa" source ="a.java" package ="es.m.p.bu.dao" value ="0"/>
> > <Value name="bb" source ="b.java" package ="es.m.p.ma.psp" value ="0"/>
> > <Value name="cc" source ="c.java" package ="es.m.p.ma.tr" value ="0"/>
> > <Value name="dd" source ="d.java" package ="es.m.p.ma.tr" value ="0"/>
> > </Values>
> > </Metric>
> > <Metric id = "TLOC" description ="Total Lines of Code" max ="-1">
> > <Value value="5039"/>
> > </Metric>
> > <Metric id = "CA" description ="Afferent Coupling" max ="50">
> > <Values per = "packageFragment" avg = "3,87" stddev = "7,165" max = "34">
> > <Value name="es.m.p.bu.vo" package ="es.m.p.bu.vo" value ="34"/>
> > <Value name="es.m.p.bu.ex" package ="es.m.p.bu.ex" value ="10"/>
> > <Value name="es.m.p.bu.dao" package ="es.m.p.bu.dao" value ="0"/>
> > <Value name="es.m.p.ma.psp" package ="es.m.p.ma.psp" value ="0"/>
> > <Value name="es.m.p.ma.tr" package ="es.m.p.ma.tr" value ="0"/>
> > </Values>
> > </Metric>
> > <Metric id = "RMD" description ="Normalized Distance" max ="0,1">
> > <Values per = "packageFragment" avg = "0,337" stddev = "0,299" max = "0,85" maxinrange="false">
> > <Value name="es.m.p.bu.vo" package ="es.m.p.bu.vo" value ="0,85" inrange="false"/>
> > <Value name="es.m.p.ws" package ="es.m.p.ws" value ="0,833" inrange="false"/>
> > <Value name="es.m.p.bu.vo" package ="es.m.p.bu.vo" value ="0,727" inrange="false"/>
> > <Value name="es.m.p.ma.tr" package ="es.m.p.ma.tr" value ="0"/>
> > </Values>
> > </Metric>
> > <Metric id = "NOC" description ="Number of Classes" max ="-1">
> > <Values per = "packageFragment" total = "72" avg = "3,13" stddev = "2,173" max = "10" maxinrange="false">
> > <Value name="es.m.p.bu.ex" package ="es.m.p.bu.ex" value ="10" inrange="false"/>
> > <Value name="es.m.p.bu.vo" package ="es.m.p.bu.vo" value ="6" inrange="false"/>
> > <Value name="es.m.p.ws" package ="es.m.p.ws" value ="6" inrange="false"/>
> > <Value name="es.m.p.ma.psp" package ="es.m.p.ma.psp" value ="1" inrange="false"/>
> > </Values>
> > </Metric>
> > <Metric id = "SIX" description ="Specialization Index" max ="-1">
> > <Values per = "type" avg = "0,204" stddev = "0,587" max = "3" maxinrange="false">
> > <Value name="qq" source ="q.java" package ="es.m.p.web.action" value ="3" inrange="false"/>
> > <Value name="ww" source ="w.java" package ="es.m.p.web.action" value ="3" inrange="false"/>
> > <Value name="ee" source ="e.java" package ="es.m.p.bu.dao" value ="1,5" inrange="false"/>
> > <Value name="rr" source ="r.java" package ="es.m.p.ma.tr" value ="0" inrange="false"/>
> > </Values>
> > </Metric>
> > <Metric id = "RMI" description ="Instability" max ="0,3">
> > <Values per = "packageFragment" avg = "0,693" stddev = "0,316" max = "1" maxinrange="false">
> > <Value name="es.m.p.bu.ma.report" package ="es.m.p.bu.ma.report" value ="1" inrange="false"/>
> > <Value name="es.m.p.web.action" package ="es.m.p.web.action" value ="1" inrange="false"/>
> > <Value name="es.m.p.ws" package ="es.m.p.ws" value ="0,167"/>
> > <Value name="es.m.p.bu.vo" package ="es.m.p.bu.vo" value ="0,15"/>
> > </Values>
> > </Metric>
> > </Metrics>
> > ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








