spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

pivoting three XML values using XSLT


As you didn't provide part of the XML as example, it's just a guess. But in case the name of the node/column in the input XML is Count, it could work if you change

<xsl:value-of select="count" />

into

<xsl:value-of select="Count" />

Update: As mentioned in the comments, the column name is count, so it's not an issue of the naming. I've just created an example input, not knowing if this matches the actual input, with a different approach to get the table.

Input XML:

<?xml version="1.0"
encoding="UTF-8"?>
<root>
  <QueryResults>
    <Data>
        <DataRow>
            <User_Created>user
1</User_Created>
            <Controlled_Drug_Name>name
1</Controlled_Drug_Name>
            <count>1</count>
        </DataRow>
        <DataRow>
            <User_Created>user
2</User_Created>
            <Controlled_Drug_Name>name
2</Controlled_Drug_Name>
            <count>2</count>
        </DataRow>
        <DataRow>
            <User_Created>user
3</User_Created>
            <Controlled_Drug_Name>name
3</Controlled_Drug_Name>
            <count>3</count>
        </DataRow>
        <DataRow>
            <User_Created>user
1</User_Created>
            <Controlled_Drug_Name>name
3</Controlled_Drug_Name>
            <count>4</count>
        </DataRow>
        <DataRow>
            <User_Created>user
2</User_Created>
            <Controlled_Drug_Name>name
3</Controlled_Drug_Name>
            <count>5</count>
        </DataRow>
        <DataRow>
            <User_Created>user
2</User_Created>
            <Controlled_Drug_Name>name
4</Controlled_Drug_Name>
            <count>5</count>
        </DataRow>
    </Data>
  </QueryResults>
</root>

XSLT:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes"
indent="yes"/>
  <xsl:key name="kUsers" match="User_Created"
use="."/>
  <xsl:key name="kRowByName" match="DataRow"
use="Controlled_Drug_Name"/>
  <xsl:variable name="users" select=
      "//User_Created
      [generate-id()
      =
      generate-id(key('kUsers', .)[1])
      ]
      "/>
  <xsl:template match="QueryResults">
     <html>
        <table>
            <thead>
                <th>Name</th>
                <xsl:apply-templates
select="$users"/>
            </thead>
            <tbody>
                <xsl:apply-templates select=
                "//DataRow
                [generate-id() = 
                 generate-id(key('kRowByName',
Controlled_Drug_Name))]">
                <xsl:sort
select="Controlled_Drug_Name"/>
                </xsl:apply-templates>
            </tbody>
       </table>
    </html>
  </xsl:template>
  <xsl:template match="User_Created">
    <th>
       <xsl:value-of select="."/>
    </th>
  </xsl:template>
  <xsl:template match="DataRow">
    <tr>
       <td>
           <xsl:value-of
select="Controlled_Drug_Name"/>
       </td>
       <xsl:apply-templates select="$users"
mode="row">
          <xsl:with-param name="nRows"
           select="key('kRowByName',
Controlled_Drug_Name)"/>
       </xsl:apply-templates>
   </tr>
  </xsl:template>
  <xsl:template match="User_Created"
mode="row">
    <xsl:param name="nRows"/>
    <td>
       <xsl:value-of select=
       
"$nRows[User_Created=current()]/count"/>
    </td>
  </xsl:template>
</xsl:stylesheet>  

Output:

<html>
<table>
  <thead>
     <th>Name</th>
     <th>user 1</th>
     <th>user 2</th>
     <th>user 3</th>
  </thead>
  <tbody>
     <tr>
        <td>name 1</td>
        <td>1</td>
        <td></td>
        <td></td>
     </tr>
     <tr>
        <td>name 2</td>
        <td></td>
        <td>2</td>
        <td></td>
     </tr>
     <tr>
        <td>name 3</td>
        <td>4</td>
        <td>5</td>
        <td>3</td>
     </tr>
     <tr>
        <td>name 4</td>
        <td></td>
        <td>5</td>
        <td></td>
     </tr>
  </tbody>
</table>
</html>

Maybe you can use this approach to work with the actual input.


Categories : Xml

Related to : pivoting three XML values using XSLT
Scala/Scalding: Pivoting data
You need to combine your two value columns into one, and then you can use .pivot. Something like this: case class v34(v3: Int, v4: Int) pipe .map(('Var3, 'Var4) -> ('V34)) { vars: (Int, Int) => v34(vars._1, vars._2) } .groupBy('Var1) { _.pivot(('Var2, 'V34) => ('x, 'y)) } .mapTo(('Var1, 'x, 'y) -> ('Var1, 'Var3x, 'Var4x, 'Var3y, 'Var4y) { vars: (String,V34,V34) =&

Categories : Scala
pivoting pandas dataframe into prefixed cols, not a MultiIndex
I figured it out. Using the data on the MultiIndex makes for a pretty clean solution: def flatten_multi_index(df): mi = df.columns suffixes, prefixes = mi.levels col_names = [prefixes[i_p] + '_' + suffixes[i_s] for (i_s, i_p) in zip(*mi.labels)] df.columns = col_names return df flatten_multi_index(pd.pivot_table(ts,index='month', columns='company')) The above version only

Categories : Python
selecting values from combobox should display html form with with loaded values from database in php
try this code... here i created example for you <script> function getComboB(sel) { var roomtype=document.getElementById("roomtype"); var value = sel.options[sel.selectedIndex].value; checkin.action = "checkin.php?item_combo="+value+"&roomtype="+value+""; checkin.submit(); } </script> <form> <select name="roomtype" id="roomtype" style="width:15

Categories : PHP
By using union select for inserting values into a temp table, how to insert values in the order I assigned?
The reason you are getting things in alphabetical order is because of the union. It does additional processing to remove duplicates. That is why union all is usually recommended. Using union all will probably almost always do what you want: INSERT INTO #tempName(Name) SELECT 'tommy' UNION ALL SELECT 'jimmy' UNION ALL SELECT 'adam' UNION ALL SELECT 'lucy'; This approach works

Categories : SQL
userHow to collect the values from html form for variable input values in google app script?
This code takes the value of an array, and creates an object: function getFormValue(formValue) { formValue = ["someInput1", "someInput2", "someInput3", "someInput4", "someInput5", "someInput6", "someInput7"]; Logger.log('formValue: ' + formValue); var myarr= {}; var count = formValue.length; Logger.log('count: ' + count); var user = {}; for(var g = 1; g<=count; g++ ) {

Categories : Javascript
Recently Add
get array result with wsdl and complexType
Same xml element in different places
How to post XML data to plone view and return xml data to sender?
Should a REST service expose a XSD for XML responses?
Querying a log file with multiple XML objects
How to set sorter of a List in Controller in SAPUI5?
XSLT Creating repetitive elements from Complex XML with Field and Metadata ids
and in a xml element
XML Nodes to be inserted with XSLT into a second Stylesheet
wso2 esb smooks un/edifact 96a EDI to XML
A complex type without an element in XSD
Convert rows of spreadsheet to separate XML files
XSLT mapping with metadata and field tags with multiple repetitive elements
Scala - Getting the error scala.xml.NodeSeq
XSLT - get value of all nodes with the same name
XSLT string join error
How do I parse XML web service in Swift?
Creating a complexType from multiple complexTypes
XSL repeating the same value but counting the correct number of different values
trying to export a complex xml from excel 2013
vb.net XML For loop
Chrome 39 XML/XSLT Renders Blank Page
How to make a drop down menu using xslt and xml?
xslt tokenize() and "Not a node item" error
Perl dies on big XML file, using STDIN
How to use custom sorter in XML views
distinct-values, contains function failed
Xslt code for fetching name value basing on the id value given in input
DonĀ“t preload images in XML (google maps API v3)
rename and send all child nodes based on value of element in child node in xslt
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.