{"id":337,"date":"2020-11-04T17:03:51","date_gmt":"2020-11-04T08:03:51","guid":{"rendered":"https:\/\/java.ihavenomoney.co.kr\/?p=337"},"modified":"2020-11-04T17:06:48","modified_gmt":"2020-11-04T08:06:48","slug":"java-transformations-sample","status":"publish","type":"post","link":"https:\/\/java.ihavenomoney.co.kr\/?p=337","title":{"rendered":"[java] Transformations sample"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-338 size-full\" src=\"https:\/\/java.ihavenomoney.co.kr\/wp-content\/uploads\/2020\/11\/java_xslt01.jpg\" alt=\"\" width=\"1068\" height=\"915\" srcset=\"https:\/\/java.ihavenomoney.co.kr\/wp-content\/uploads\/2020\/11\/java_xslt01.jpg 1068w, https:\/\/java.ihavenomoney.co.kr\/wp-content\/uploads\/2020\/11\/java_xslt01-300x257.jpg 300w, https:\/\/java.ihavenomoney.co.kr\/wp-content\/uploads\/2020\/11\/java_xslt01-1024x877.jpg 1024w, https:\/\/java.ihavenomoney.co.kr\/wp-content\/uploads\/2020\/11\/java_xslt01-768x658.jpg 768w, https:\/\/java.ihavenomoney.co.kr\/wp-content\/uploads\/2020\/11\/java_xslt01-660x565.jpg 660w\" sizes=\"auto, (max-width: 1068px) 100vw, 1068px\" \/><\/p>\n<h4>html \ub85c \ubcf4\uae30<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-339\" src=\"https:\/\/java.ihavenomoney.co.kr\/wp-content\/uploads\/2020\/11\/java_xslt02.jpg\" alt=\"\" width=\"650\" height=\"287\" srcset=\"https:\/\/java.ihavenomoney.co.kr\/wp-content\/uploads\/2020\/11\/java_xslt02.jpg 798w, https:\/\/java.ihavenomoney.co.kr\/wp-content\/uploads\/2020\/11\/java_xslt02-300x132.jpg 300w, https:\/\/java.ihavenomoney.co.kr\/wp-content\/uploads\/2020\/11\/java_xslt02-768x339.jpg 768w, https:\/\/java.ihavenomoney.co.kr\/wp-content\/uploads\/2020\/11\/java_xslt02-660x291.jpg 660w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<h4>persons.xml<\/h4>\n<pre class=\"lang:xhtml decode:true\">&lt;breakfast_menu&gt;\r\n\r\n&lt;food&gt;\r\n&lt;name&gt;Belgian Waffles&lt;\/name&gt;\r\n&lt;price&gt;$5.95&lt;\/price&gt;\r\n&lt;description&gt;Two of our famous Belgian Waffles with plenty of real maple syrup&lt;\/description&gt;\r\n&lt;calories&gt;650&lt;\/calories&gt;\r\n&lt;\/food&gt;\r\n\r\n&lt;food&gt;\r\n&lt;name&gt;Strawberry Belgian Waffles&lt;\/name&gt;\r\n&lt;price&gt;$7.95&lt;\/price&gt;\r\n&lt;description&gt;Light Belgian waffles covered with strawberries and whipped cream&lt;\/description&gt;\r\n&lt;calories&gt;900&lt;\/calories&gt;\r\n&lt;\/food&gt;\r\n\r\n&lt;food&gt;\r\n&lt;name&gt;Berry-Berry Belgian Waffles&lt;\/name&gt;\r\n&lt;price&gt;$8.95&lt;\/price&gt;\r\n&lt;description&gt;Light Belgian waffles covered with an assortment of fresh berries and whipped cream&lt;\/description&gt;\r\n&lt;calories&gt;900&lt;\/calories&gt;\r\n&lt;\/food&gt;\r\n\r\n&lt;food&gt;\r\n&lt;name&gt;French Toast&lt;\/name&gt;\r\n&lt;price&gt;$4.50&lt;\/price&gt;\r\n&lt;description&gt;Thick slices made from our homemade sourdough bread&lt;\/description&gt;\r\n&lt;calories&gt;600&lt;\/calories&gt;\r\n&lt;\/food&gt;\r\n\r\n&lt;food&gt;\r\n&lt;name&gt;Homestyle Breakfast&lt;\/name&gt;\r\n&lt;price&gt;$6.95&lt;\/price&gt;\r\n&lt;description&gt;Two eggs, bacon or sausage, toast, and our ever-popular hash browns&lt;\/description&gt;<\/pre>\n<h4>persons.xsl<\/h4>\n<pre class=\"lang:xhtml decode:true \">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;html xsl:version=\"1.0\" xmlns:xsl=\"http:\/\/www.w3.org\/1999\/XSL\/Transform\"&gt;\r\n&lt;body style=\"font-family:Arial;font-size:12pt;background-color:#EEEEEE\"&gt;\r\n&lt;xsl:for-each select=\"breakfast_menu\/food\"&gt;\r\n  &lt;div style=\"background-color:teal;color:white;padding:4px\"&gt;\r\n    &lt;span style=\"font-weight:bold\"&gt;&lt;xsl:value-of select=\"name\"\/&gt; - &lt;\/span&gt;\r\n    &lt;xsl:value-of select=\"price\"\/&gt;\r\n    &lt;\/div&gt;\r\n  &lt;div style=\"margin-left:20px;margin-bottom:1em;font-size:10pt\"&gt;\r\n    &lt;p&gt;\r\n    &lt;xsl:value-of select=\"description\"\/&gt;\r\n    &lt;span style=\"font-style:italic\"&gt; (&lt;xsl:value-of select=\"calories\"\/&gt; calories per serving)&lt;\/span&gt;\r\n    &lt;\/p&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/xsl:for-each&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h4>XsltTransformation.java<\/h4>\n<pre class=\"lang:java decode:true \">import org.w3c.dom.Document;\r\n \r\nimport javax.xml.parsers.DocumentBuilder;\r\nimport javax.xml.parsers.DocumentBuilderFactory;\r\nimport javax.xml.transform.Transformer;\r\nimport javax.xml.transform.TransformerFactory;\r\nimport javax.xml.transform.dom.DOMSource;\r\nimport javax.xml.transform.stream.StreamResult;\r\nimport javax.xml.transform.stream.StreamSource;\r\nimport java.io.File;\r\n\r\npublic class XsltTransformation {\r\n\r\n\tprivate static Document document;\r\n\t\r\n\tpublic static void main(String[] args)  throws Exception {\r\n\r\n\t\tDocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\r\n\t\t \r\n\t    File xml = new File(\"D:\\\\persons.xml\");\r\n\t    File xsl = new File(\"D:\\\\persons.xsl\");\r\n\t \r\n\t    DocumentBuilder builder = factory.newDocumentBuilder();\r\n\t    document = builder.parse(xml);\r\n\t \r\n\t    \/\/ Use a Transformer for output\r\n\t    TransformerFactory transformerFactory = TransformerFactory.newInstance();\r\n\t    StreamSource style = new StreamSource(xsl);\r\n\t    Transformer transformer = transformerFactory.newTransformer(style);\r\n\t \r\n\t    DOMSource source = new DOMSource(document);\r\n\t    StreamResult result = new StreamResult(System.out);\r\n\t    transformer.transform(source, result);\r\n\t}\r\n\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>html \ub85c \ubcf4\uae30 persons.xml &lt;breakfast_menu&gt; &lt;food&gt; &lt;name&gt;Belgian Waffles&lt;\/name&gt; &lt;price&gt;$5.95&lt;\/price&gt; &lt;description&gt;Two of our famous Belgian Waffles with plenty of real maple syrup&lt;\/description&gt; &lt;calories&gt;650&lt;\/calories&gt; &lt;\/food&gt; &lt;food&gt; &lt;name&gt;Strawberry Belgian Waffles&lt;\/name&gt; &lt;price&gt;$7.95&lt;\/price&gt; &lt;description&gt;Light Belgian waffles covered with strawberries and whipped cream&lt;\/description&gt; &lt;calories&gt;900&lt;\/calories&gt; &lt;\/food&gt; &lt;food&gt; &lt;name&gt;Berry-Berry Belgian Waffles&lt;\/name&gt; &lt;price&gt;$8.95&lt;\/price&gt; &lt;description&gt;Light Belgian waffles covered with an assortment of fresh berries and &hellip;<br \/><a href=\"https:\/\/java.ihavenomoney.co.kr\/?p=337\" class=\"more-link pen_button pen_element_default pen_icon_arrow_double\"><span class=\"screen-reader-text\">[java] Transformations sample<\/span> \ub354\ubcf4\uae30<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-337","post","type-post","status-publish","format-standard","hentry","category-java-xslt-"],"_links":{"self":[{"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337"}],"version-history":[{"count":5,"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":344,"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions\/344"}],"wp:attachment":[{"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}