Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 27th, 2007, 03:03 AM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please help me

 HI, I need to transform a PMML file to SVG format but I´dont know how, please help me.....

<?xml version="1.0" ?>
  <PMML version="3.1" xmlns="http://www.dmg.org/PMML-3_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Header copyright="dmg.org"/>
    <DataDictionary numberOfFields="3">
      <DataField name="marital status" optype="categorical" dataType="string">
          <Value value="s"/>
          <Value value="d"/>
          <Value value="m"/>
      </DataField>
      <DataField name="age" optype="continuous" dataType="double"/>
      <DataField name="salary" optype="continuous" dataType="double"/>
    </DataDictionary>
    <ClusteringModel modelName="Mini Clustering"
          functionName="clustering"
          modelClass="centerBased"
          numberOfClusters="2">
      <MiningSchema>
               <MiningField name="marital status"/>
               <MiningField name="age"/>
               <MiningField name="salary"/>
      </MiningSchema>

      <ComparisonMeasure kind="distance">
               <squaredEuclidean/>
      </ComparisonMeasure>

      <ClusteringField field="marital status"
                      compareFunction="absDiff"/>
      <ClusteringField field="age"
                      compareFunction="absDiff"/>
      <ClusteringField field="salary"
                      compareFunction="absDiff"/>
      <CenterFields>
        <DerivedField name="c1" optype="continuous" dataType="double">
          <NormContinuous field="age">
               <LinearNorm orig="45" norm="0"/>
               <LinearNorm orig="82" norm="0.5"/>
               <LinearNorm orig="105" norm="1"/>
          </NormContinuous>
        </DerivedField>
        <DerivedField name="c2" optype="continuous" dataType="double">
          <NormContinuous field="salary">
               <LinearNorm orig="39000" norm="0"/>
               <LinearNorm orig="39800" norm="0.5"/>
               <LinearNorm orig="41000" norm="1"/>
          </NormContinuous>
        </DerivedField>
        <DerivedField name="c3" optype="continuous" dataType="double">
          <NormDiscrete field="marital status" value="m"/>
        </DerivedField>
        <DerivedField name="c4" optype="continuous" dataType="double">
          <NormDiscrete field="marital status" value="d"/>
        </DerivedField>
        <DerivedField name="c5" optype="continuous" dataType="double">
          <NormDiscrete field="marital status" value="s"/>
        </DerivedField>
      </CenterFields>
      <MissingValueWeights>
        <Array n="5" type="real">1 1 1 1 1</Array>
      </MissingValueWeights>
      <Cluster name="marital status is d or s">
        <Array n="5" type="real">
               0.524561 0.486321 0.128427 0.459188 0.412384</Array>
      </Cluster>
      <Cluster name="marital status is m">
        <Array n="5" type="real">
               0.69946 0.419037 0.591226 0.173521 0.235253</Array>
      </Cluster>
    </ClusteringModel>
  </PMML>

 
Old May 27th, 2007, 04:00 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You'll need to explain (a) what output you want, and (b) where you are having difficulty. I'd suggest you simplify the problem a bit, and also think about yor question from the point of view of someone trying to answer it. I could write you some code that transformed your data into SVG, but (a) it would be quite unlike the SVG representation that you want to achieve, and (b) it wouldn't help you over your learning difficulties.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 28th, 2007, 10:59 PM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default


sorry not to make understand me… what I need specifically is how I can defining a XSLT to transform a document PMML into a SVG that allows me to visualize the model graphically, or a graph of pie, bar charts or any other.
sorry about my English because I don´t speak English very well

 
Old May 29th, 2007, 03:27 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your English isn't a problem.

If this were an assignment that I was being paid for, I would budget a couple of days for it, and I would start by asking for a more detailed statement of requirements.

But it's not an assignment I'm being paid for, it's a project of yours where you need help. So you need to explain where you are stuck, what part of the problem are you having difficulty with? What part of the XSLT language don't you understand?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 31st, 2007, 10:28 AM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I need exactly to transform previous pmml into a cluster graph and showing to both cluster that she gives this pmml me like exit in a system of coordinates x,y. but I don´t know how making it, and if you were so amiable to solve this problem for me , the problem is that I specifically need that example for in a moment and don´t know anything about the subject... please help me I need you very most.

 
Old May 31st, 2007, 10:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm sorry, I do my best here to try and help people solve simple coding problems, but I can't write complete stylesheets for people, let alone design them from a very incomplete statement of requirements. That's consultancy, and I make my living from it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 1st, 2007, 01:53 AM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is my XML source:

Quote:
quote:
<ClusteringModel modelName="Mini Clustering" functionName="clustering" modelClass="centerBased" numberOfClusters="2">
        <MissingValueWeights>
            <Array n="5" type="real">1 1 1 1 1</Array>
        </MissingValueWeights>
        <Cluster name="marital status is d or s">
            <Array n="5" type="real">
                0.524561 0.486321 0.128427 0.459188 0.412384
            </Array>

</Cluster>
        <Cluster name="marital status is m">
            <Array n="5" type="real">
               0.69946 0.419037 0.591226 0.173521 0.235253</Array>

        </Cluster>
</ClusteringModel>
and this is my XSLT source:

Quote:
quote:
<?xml version="1.0" encoding="utf-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >

    <xsl:template match="ClusteringModel">
        <xsl:variable name="noIter" select="Array/n"/>
        <svg width="200px" height="250px">
            <g id="bar" transform="translate(0,200)">
                    <xsl:for-each select="Array/n">
                        <xsl:variable name="val" select="Cluster/Array"/>
                         <rect x="$val" y="-{$val}"
                                 fill="black" width="0.1"
                                 height="0.1" stroke="black"
                                 stroke-width="2"/>
                    </xsl:for-each>
            </g>
        </svg>
    </xsl:template>

</xsl:transform>
That I need is: how can I read the set value of Array tag because I try with this xslt code but I can't obtain the Array's values as number. for build the svg output.

Thanks for your help

 
Old June 1st, 2007, 03:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's a shame that the items in Array haven't been marked up as individual elements, that would have made your life easier.

In XSLT 2.0 it's easy to split the list into tokens using the tokenize() function. For XSLT 1.0 you need a recursive template to do the job, you can find one called str:tokenize at www.exslt.org.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 2nd, 2007, 01:19 AM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello:

Thanks for your last reply. It help me so much.

But I have some another problem, when I store the value into variable "tokens" after do the "split" function, I not obtain all values of the array, I just obtain the first value for each iteration.

I did this code in static form:

    <?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="1.0"
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:str="http://exslt.org/strings"
                  extension-element-prefixes="str"
 xmlns:pmml="http://www.dmg.org/PMML-3_0">

    <xsl:import href="split/str.split.xsl"/>

    <xsl:template match="pmml:ClusteringModel">
        <svg width="200px" height="250px">
        <xsl:for-each select="pmml:Cluster ">

            <xsl:variable name="value" select="pmml:Array"/>

            <xsl:variable name="tokens">
                <xsl:call-template name="str:split">
                    <xsl:with-param name="string" select="$value"/>
                    <xsl:with-param name="pattern" select="','"/>
                </xsl:call-template>
            </xsl:variable>

            <g id="bar" transform="translate(0,200)">
                <xsl:for-each select="$tokens">

                        <xsl:variable name="XY1" select="token[1]"/>
                        <rect x="{$XY1 * 100}" y="-{$XY1 * 100}"
                                fill="black" width="0.1"
                                height="0.1" stroke="black"
                                stroke-width="2"/>

                        <xsl:variable name="XY2" select="token[2]"/>
                        <rect x="{$XY2 * 100}" y="-{$XY2 * 100}"
                                fill="black" width="0.1"
                                height="0.1" stroke="black"
                                stroke-width="2"/>

                        <xsl:variable name="XY3" select="token[3]"/>
                        <rect x="{$XY3 * 100}" y="-{$XY3 * 100}"
                                fill="black" width="0.1"
                                height="0.1" stroke="black"
                                stroke-width="2"/>

                        <xsl:variable name="XY4" select="token[4]"/>
                        <rect x="{$XY4 * 100}" y="-{$XY4 * 100}"
                                fill="black" width="0.1"
                                height="0.1" stroke="red"
                                stroke-width="2"/>

                        <xsl:variable name="XY5" select="token[5]"/>
                        <rect x="{$XY5 * 100}" y="-{$XY5 * 100}"
                                fill="black" width="0.1"
                                height="0.1" stroke="red"
                                stroke-width="2"/>

                </xsl:for-each>
            </g>
        </xsl:for-each>
        </svg>
    </xsl:template>

</xsl:stylesheet>


 Now my question is how I can obtain the same result in dynamic form?


 
Old June 2nd, 2007, 05:45 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You seem to be using comma as a separator in your call to str:split whereas your data uses a space. Don't know if that's the whole problem though.

A conformant XSLT 1.0 processor will not allow you to use a result tree fragment in this way; you need to convert it to a nodeset using the exslt:node-set() function. Some processors allow you to get away with it. But since it's outside the standard, it may not be doing what you expect.

A useful diagnostic is to insert

<debug>
  <xsl:copy-of select="$tokens"/>
<debug>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.