1

I'm exploring the Magento 2 CLI and I don't know how could I apply the command below in real life?

bin/magento dev:xml:convert

Can you show me some example?

Thanks!

1
  • So, you want to make own comand,right?
    – kunj
    Jun 3, 2018 at 16:46

1 Answer 1

3

The command is used to transform XML to XSLT. it is a way to transform the XML document into other formats such as XHTML.

Take an example

catalog.xml

<?xml version="1.0" encoding="UTF-8"?>
  <catalog>
    <product>
      <name>Product 1</name>
      <status>Enabled</status>
      <price>100.80</price>
    </product>
    <product>
      <name>Product 2</name>
      <status>Enabled</status>
      <price>230.45</price>
    </product>  
  </catalog>

catalogxslt.xslt

  <?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
  <html> 
  <body>
    <h2>Product Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th style="text-align:left">Name</th>
        <th style="text-align:left">Price</th>
      </tr>
      <xsl:for-each select="catalog/product">
      <tr>
        <td><xsl:value-of select="name"/></td>
        <td><xsl:value-of select="price"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
  </xsl:template>
  </xsl:stylesheet>

after this run the below command:

bin/magento dev:xml:convert catalog.xml catalogxslt.xslt

Output:

    <?xml version="1.0"?>
    <html>
        <body>
            <h2>Product Collection</h2>
            <table border="1">
                <tr bgcolor="#9acd32">
                    <th style="text-align:left">Name</th>
                    <th style="text-align:left">Price</th>
                </tr>
                <tr>
                    <td>Product 1</td>
                    <td>100.80</td>
                </tr>
                <tr>
                    <td>Product 2</td>
                    <td>230.45</td>
                </tr>
            </table>
        </body>
    </html>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.