-1

I want to sort out the values of "number" by the Position/or first come in the XML document of the ID values and display it. Is there a way to do this.

Here is my XML document

<?xml version="1.0" encoding="UTF-8"?>
<JobList>
<Job ID="2" />                this is position 1
<Job ID="3" />                this is position 2
<Job ID="5" />                this is position 3
<Job ID="4" />                this is position 4
<Tool number="10" />
<Tool number="24" />
<Tool number="28" />
<Tool number="75" />
</JobList>

Desired Result:

<?xml version="1.0" encoding="UTF-8"?>
<JobList>
<Job ID="2" />               
<Job ID="3" />               
<Job ID="5" />                
<Job ID="4" />               
<Tool number="28" />
<Tool number="10" />
<Tool number="24" />
<Tool number="75" />
</JobList>

Here is my XSL document:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsl:stylesheet version="1.0"    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" encoding="UTF-8" method="xml" />
<xsl:param name="REPORT">joblist</xsl:param>
<xsl:param name="LOCALE">en-US</xsl:param>
<xsl:param name="FORMAT">html</xsl:param>
<xsl:param name="CAPTURE">example,job</xsl:param>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Joblist Report</title>
    <style type="text/css">
    body {font-family: Arial;}
    </style>
    </head>
  <body>
    <xsl:apply-templates />
  </body>
</html>
 </xsl:template>
 <xsl:template match="JobList">
 <div>
  <table width="100" border="1">
    <thead>
      <tr>
        <td>
          <xsl:value-of select="Sorted Numbers" />
        </td>
      </tr>
    </thead>
    <tbody>
        <xsl:variable name="vsortOrder" select="//Job[@ID]" />
        <xsl:for-each select="Tool">                      
        <xsl:sort select="@number" order="{$vsortOrder}" data-type="number" />
      <tr>
        <td>
            <xsl:value-of select="@number" />
        </td>
      </tr>
      </xsl:for-each>
    </tbody>
  </table>
</div>
  </xsl:template>
  </xsl:stylesheet>
Alex W
  • 17
  • 4
  • Please show us the actual input code, instead of describing it - and show us also the expected output. -- "*my XSL 1.0 table*" Is this a way to say you're using an XSLT 1.0 processor? If so, which one? – michael.hor257k Dec 17 '16 at 21:02
  • I still see no XML input, no expected output, and no information about the actual processor you will be using. – michael.hor257k Dec 17 '16 at 21:20
  • there is no XML file atleast as I know. there is this editer(that I am using) that came with a computer program (that has certain attributes specified) to help make this XSL spreadsheet. – Alex W Dec 17 '16 at 21:32
  • There must be XML input, otherwise you're not using XSLT. If you cannot access it directly, use the *identity transform* template to get it. And see here how to identify your processor: http://stackoverflow.com/questions/25244370/how-can-i-check-which-xslt-processor-is-being-used-in-solr/25245033#25245033 – michael.hor257k Dec 17 '16 at 21:35
  • the vendor is "Microsoft" and the version is "1" using the link you gave me. I am still trying to figure out the XML issue. I know this program generates its own XSL file and saves it as an HTML file. – Alex W Dec 17 '16 at 21:51
  • Basically I am just making a .XSL template for the program to input the data into automatically. I am just altering this template to get the data where I want using its already preset attributes and making formula's to alter the data. – Alex W Dec 17 '16 at 22:00
  • I suggest - again - that you use a stylesheet that contains nothing but the *identity transform* template and post the result (within your question). Otherwise we are working blind and I for one don't know what to suggest. – michael.hor257k Dec 17 '16 at 22:03
  • I am making it in a Editer that saves it as XSL so even a blank sheet and saving it would input what I gave you earlier but without any attributes and such. I honestly dont know what else I can give to help. I might be on my own. – Alex W Dec 17 '16 at 22:17
  • You say you have an attribute x that contains y. How do *you* know that? – michael.hor257k Dec 17 '16 at 22:21
  • because I have a notepad file that came with the program that tells me what attribute displays what so: – Alex W Dec 17 '16 at 22:24
  • so: "@cfg.jobID" contains the JOBID of the program and "@number"contains a number the I specify in the program. – Alex W Dec 17 '16 at 22:27
  • Well, I don't understand *your* description of the two attributes contents. If you cannot show us a **copy** of it, then I don't know how to handle it. – michael.hor257k Dec 17 '16 at 22:28
  • this is copy and pasted from the notepad file it is a pretty big notepad file so I didnt want to display it on here unless I have too. Job@cfg.JOBID Job ID Tool@number Tool number – Alex W Dec 17 '16 at 22:30
  • I meant a copy of the actual contents of the two attributes. – michael.hor257k Dec 17 '16 at 22:37
  • I was hoping to use the XSL Sort element to try and get my desired result so trying to sort the values of "@number" with the order (only order) of "@cfg.jobid". I just dont know the syntex very well or how I would write that. I took a look at some tutorials but still cant get it to work. – Alex W Dec 17 '16 at 22:40
  • the contents change periodically so I cant give you there actuall value of those attributes just that the output is always a number from 1-5 or more whatever is needed by the program. – Alex W Dec 17 '16 at 22:44
  • XSLT sees the contents of an attribute as a single, meaningless string. There are no individual values you can sort, unless you pre-process the string and *tokenize* it. Since you are unable to show us what the string looks like, that's all I can say about it. – michael.hor257k Dec 17 '16 at 22:49
  • I moreless just need "@number" to show up as the same position as "cfg.jobid" or trying to sort it somehow by position of that attribute. – Alex W Dec 17 '16 at 22:54
  • Please delete this question, as you have (quite correctly) asked a new one. – michael.hor257k Jan 02 '17 at 22:05

1 Answers1

0

Try creating a XSLT file that contains the identity template as follows. Then run it with your input file. This will create output XML. Then give us a snippet that contains at least a few of the nodes you are working with; like JobList, Tool and job.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes" method="xml" version="1.0" omit-xml-declaration="no"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>   
John Ernst
  • 1,206
  • 1
  • 7
  • 11