B
B
blessmemary2021-06-09 18:00:47
XSL & XSLT
blessmemary, 2021-06-09 18:00:47

How to transform XML with XSL?

Please help transform the given XML:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='stock.xsl'?> 
<stock>
  <parts>
    <type id="cpu" name="processor"/>
    <type id="vcard" name="video"/>
    <type id="acard" name="audio"/>
    <type id="storage" name="memory"/>
  </parts>
  <shelf>
    <row assembly="Москва">
      <part type="cpu">Core i7</part>
      <part type="vcard">GeForce RTX 30</part>
      <part type="storage">4Gb</part>
    </row>
    <row assembly="Москва">
      <part type="cpu">Core i5</part>
      <part type="vcard">GeForce GTX 1050</part>
      <part type="acard">DEXP 4.0 PCI</part>
      <part type="storage">8Gb</part>
    </row>
    <row assembly="Калуга">
      <part type="cpu">AMD Radeon RX 6000</part>
      <part type="vcard">GeForce RX 550</part>
      <part type="storage">4Gb</part>
    </row>
  </shelf>
</stock>


in XML of the form:

<shop>
  <products>
    <product no='1' from='Москва'>
      <processor>Core i7</processor>
      <video>GeForce RTX 30</video>
      <memory>4Gb</memory>
    </product>
    ...
  </products>
</shop>

where the no attribute is the index number of the current product element
the from attribute is the value of the assembly attribute of the current element element row
the element names within the product element are the value of the name attribute of the type element whose id attribute matches the current part element's type attribute.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question