logo
down
shadow

XML data to tables using PHP with multiple elements, output should be based on the number of X elements


XML data to tables using PHP with multiple elements, output should be based on the number of X elements

By : MarceeMarc
Date : November 22 2020, 10:54 AM
Any of those help If you want 1 row per per , then you need to loop through the inside the . To get the id use ->getAttribute('id') -
code :
<?php
$dom = new DOMDocument();
$dom->load('person.xml');
$xpath = new DOMXpath($dom);

echo <<<EOF
<table border="1" cellspacing="2" cellpadding="2">   <tr>
    <th>Person ID</th>
    <th>Person Name</th>
    <th>Person LastName </th>
    <th>Code Numbers</th>
    </tr>
EOF;

$persons = $xpath->evaluate('//person');
foreach ($persons as $person) {
    //loop through each <code_number>
    foreach ($xpath->evaluate('./codes/code_number', $person) as $code_number) {
        echo '<tr>', "\n";
        echo '<td>', htmlspecialchars($person->getAttribute('id')), '</td>', "\n";
        echo '<td>', htmlspecialchars($xpath->evaluate('string(./person_name)', $person)), '</td>', "\n";
        echo '<td>', htmlspecialchars($xpath->evaluate('string(./person_lastname)', $person)), '</td>', "\n";
        echo '<td>'.htmlspecialchars($code_number->nodeValue).'</td>', "\n";
        echo '</tr>', "\n"; 
    }
}
echo '</table>';
?>


Share : facebook icon twitter icon
How to output the number of elements based on a certain criteria?

How to output the number of elements based on a certain criteria?


By : eerapu
Date : March 29 2020, 07:55 AM
like below fixes the issue Try moving your totalSuccessArray definition outside your for loop and then push()ing the elements onto it like this:
code :
cars=["BMW","Volvo","Saab","Ford","Saab"];
var count=0;
var totalSuccessArray= new Array();
for (var i=0;i<cars.length;i++)
{
    document.write(cars[i] + "<br>");
    if(cars[i]=="Saab") {
        totalSuccessArray.push(cars[i]);
        count++;
    }   
}
Create parent-child elements based on attribute-values and suppress duplicate elements in output

Create parent-child elements based on attribute-values and suppress duplicate elements in output


By : Xqrz
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Here is a shorter/simpler (no xsl:if, no xsl:key, no generate-id()) solution:
code :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:my="my:my" extension-element-prefixes="my">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>
 <my:names>
   <n>A</n>
   <n>B</n>
   <n>C</n>
 </my:names>

 <xsl:template match="*">
  <Root><xsl:apply-templates/></Root>
 </xsl:template>

 <xsl:template match="/*/*">
  <ObjectData><xsl:apply-templates/></ObjectData>
 </xsl:template>

 <xsl:template match="Property[not(contains(@Name, '.'))]">
  <xsl:element name="{@Name}">
   <xsl:value-of select="@Value"/>
  </xsl:element>
 </xsl:template>

 <xsl:template match="Property">
  <xsl:element name="{substring-before(@Name, '.')}">
    <xsl:element name="{substring-after(@Name, '.')}">
       <xsl:value-of select="@Value"/>
    </xsl:element>
    <xsl:apply-templates mode="descr"  select=
     "../*[@Name = concat(substring-before(current()/@Name, '.'),'.','Description')]"/>
  </xsl:element>
 </xsl:template>

 <xsl:template match=
  "Property[string(@Value) and contains(@Name, '.')
  and substring-before(@Name, '.') = document('')/*/my:names/*]
  [1]
  ">
   <Destination>
       <Type><xsl:value-of select="substring-before(@Name, '.')"/></Type>
       <xsl:element name="{substring-after(@Name, '.')}">
           <xsl:value-of select="@Value"/>
       </xsl:element>
     <xsl:apply-templates mode="descr" select=
     "../*[@Name = concat(substring-before(current()/@Name, '.'),'.','Description')]"/>

   </Destination>
 </xsl:template>

  <xsl:template match=
  "Property[contains(@Name, '.')
          and substring-before(@Name, '.') = document('')/*/my:names/*
          and not(string(@Value))
           ]"/>
  <xsl:template match=
  "Property[contains(@Name, '.')
          and substring-before(@Name, '.') = document('')/*/my:names/*
          and string(@Value)
           ][not(position() = 1)]"/>
 <xsl:template match="*[substring-after(@Name,'.') = 'Description']"/>

 <xsl:template match="*" mode="descr">
  <Description><xsl:apply-templates select="@Value"/></Description>
 </xsl:template>
</xsl:stylesheet>
<Data>
    <Object>
        <Property Name="Id" Value="001"/>
        <Property Name="P.Id" Value="Id P"/>
        <Property Name="P.Description" Value="Descr P"/>
        <Property Name="A.Id" Value="Id A" />
        <Property Name="A.Description" Value="Descr A"/>
        <Property Name="B.Id" Value="Id B"/>
        <Property Name="B.Description" Value="Descr B"/>
        <Property Name="C.Id" Value="" />
        <Property Name="C.Description" Value=""/>
    </Object>
    <Object>
        <Property Name="Id" Value="002"/>
        <Property Name="P.Id" Value="Id P"/>
        <Property Name="P.Description" Value="Descr P"/>
        <Property Name="A.Id" Value="" />
        <Property Name="A.Description" Value=""/>
        <Property Name="B.Id" Value="Id B"/>
        <Property Name="B.Description" Value="Descr B"/>
        <Property Name="C.Id" Value="Id C" />
        <Property Name="C.Description" Value="Descr C"/>
    </Object>
</Data>
<Root>
   <ObjectData>
      <Id>001</Id>
      <P>
         <Id>Id P</Id>
         <Description>Descr P</Description>
      </P>
      <Destination>
         <Type>A</Type>
         <Id>Id A</Id>
         <Description>Descr A</Description>
      </Destination>
   </ObjectData>
   <ObjectData>
      <Id>002</Id>
      <P>
         <Id>Id P</Id>
         <Description>Descr P</Description>
      </P>
      <Destination>
         <Type>B</Type>
         <Id>Id B</Id>
         <Description>Descr B</Description>
      </Destination>
   </ObjectData>
</Root>
SAS Create Multiple Tables Based on Given Character Elements

SAS Create Multiple Tables Based on Given Character Elements


By : CharH
Date : March 29 2020, 07:55 AM
wish of those help , You could replace your array with a macro variable string:
code :
%let period=day week month year;
%MACRO sqlloop;
  proc sql;
    %DO k = 1 %TO %sysfunc(countw(&period.)); /*fixed extra s*/
      %LET bucket = %scan(&period.,&k.);
      CREATE TABLE output.t_&bucket AS (
        SELECT INTNX( "&bucket.", date_field, 0, 'E') AS test FROM table);
    %END;
  quit;
%MEND;
%sqlloop
Shiny - Editing rhandsontable tables with multiple input and output elements

Shiny - Editing rhandsontable tables with multiple input and output elements


By : Question
Date : March 29 2020, 07:55 AM
Hope this helps I think you were almost there. You can, however, not use an input for creating a reactive value. But this is anyways not eneded and you can initiate it with a NULL.
code :
library(shiny)
library(rhandsontable)

ui <- fluidPage(
  numericInput("x", "number of values", 2),
  rHandsontableOutput('table'),
  textOutput('result'),
  plotOutput('plot'),
  actionButton("recalc", "generate new random vals and calculate")
)


server <- function(input,output,session)({
  values <- reactiveValues(data = NULL) ## assign it with NULL

  ## button press resets now the data frame
  observeEvent(input$recalc, { 
    values$data$x <- 0
  })

  ## changes in numericInput sets all (!) new values
  observe({
    req(input$x)
    values$data <- data.frame(x = runif(input$x))
  })

  observe({
    if(!is.null(input$table))
      values$data <- hot_to_r(input$table)
  })


  output$table <- renderRHandsontable({
    req(values$data)
    rhandsontable(values$data)
  })


  output$result <- renderText({
    req(values$data)
    sum(values$data)
  })

  output$plot <- renderPlot({
    req(values$data)
    barplot(values$data$x)
  })

})

shinyApp(ui = ui, server = server)
How can I group by elements based on multiple columns in pandas dataframe and save the number of elements of each group

How can I group by elements based on multiple columns in pandas dataframe and save the number of elements of each group


By : user3253642
Date : March 29 2020, 07:55 AM
may help you . Use GroupBy.transform to get an equal length vector back, and assing it as new column:
code :
df['Count'] = df.groupby(df.columns.tolist())['Col1'].transform('size')
   Col1  Col2  Col3  Count
0     1     2     1      2
1     1     2     1      2
2     1     3     1      1
3     2     4     1      1
Related Posts Related Posts :
  • How to make a sitemap using zend framework 1
  • Laravel: array to Model with relationship tree
  • $_SERVER['DOCUMENT_ROOT'] vs $path = $_SERVER['DOCUMENT_ROOT']
  • What is the best way to store multiple checkbox values in the database and work with it later on
  • Why does foreach copy the array when we did not modify it in the loop?
  • Receive Jquery/Ajax Post Request in PHP
  • How to better use the if(!empty()){ //codes} statement
  • PHP error mysql_close() boolean given
  • Move an image file from one server to another using PHP
  • PHP: Encoding non ISO-8859-1 charactrers into utf8
  • Handling MySQL errors in PHP
  • Object orientated mysql num_rows query in one line
  • Remove not closed html elements from end of text
  • Generate random ENUM value [PHP, MySQL]
  • Deleting data from table using jQuery and SQL
  • How to make sure the constructor is executed when I'm trying to reach a static property?
  • Trying to understand arrow next to PHP function
  • Form using external php file to show "Sucess"
  • WooCommerce - new shipping method - how to query individual product weights
  • Common integer representation over variable casting?
  • PHP - Prevent client from tampering the ID of a form
  • unexpected T_PUBLIC error
  • Types of testcases in PHPUnit
  • keeping a LDAP user logged in with PHP session
  • Detect if browser supports WebP format? (server side)
  • real_escape_string not cleaning up entered text
  • E-commerce products filter
  • Why having more than one test method in a file using Laravel raises error?
  • PHP Escaped special characters to html
  • Basic prepared statement not INSERTING
  • PHP combobox not showing in HTML table
  • MySql PHP row request to variable
  • Join two tables with one table has multiple rows matching
  • Looping through users with Instagram API requests is REALLY slow
  • Unable to add 30 days to date within loop
  • Return from mysqli_query() into array
  • php rename() function returns "No such file or directory" error
  • form submit inside navigation menu
  • PHP: reasons to use GET and POST request at the same time?
  • Is break; required after die() php
  • little depth of session in php
  • Authentication Logon page not working using PHP and Oracle on Apache / Windows 2008
  • Magento reindexing error product flat data
  • Laravel 4: Running composer when deploying to Heroku
  • Long Polling or WebSockets
  • How to use mysqli_stmt_bind_param for integers, boolean, etc
  • Determining the content of a link
  • MYSQL and PHP update events?
  • PHP explode all square bracket
  • Transparent hexagon-masked collage using PHP GD
  • Plugins or text do NOT show up on custom wordpress template
  • inserting data into mysqli database
  • Two arguments to closure function laravel
  • UnClear image exported by ffmpeg from mp4 file
  • is the time of computer and localhost same?
  • change custom data- value after ajax post success
  • Can We Restrict PHP Variables to accept only certain type of values
  • csv file is inserting a blank row in the last of other rows into mysql table
  • How to convert special characters in xml using php?
  • Mcrypt are very confusing
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org