udemy xslt
エミュポータル -エミュレータ総合情報サイト-
ホーム

Udemy Xslt | _best_

Sunday morning. The final boss. He needed to generate a CSV header row, then loop through each ShipmentOrder , and for each Package , produce a line with OrderID, TrackingNumber, ItemSKU, Quantity . But some Package elements had no Item (empty shipments), and some had ten.

<xsl:template match="hcl:ShipmentOrder"> <xsl:for-each select="hcl:Packages/hcl:Package"> <xsl:value-of select="../../hcl:OrderID"/>, <xsl:value-of select="hcl:TrackingNumber"/>, <xsl:for-each select="hcl:Items/hcl:Item"> <xsl:value-of select="hcl:SKU"/>, <xsl:value-of select="hcl:Qty"/> <xsl:if test="not(position()=last())">|</xsl:if> </xsl:for-each> <xsl:text> </xsl:text> </xsl:for-each> </xsl:template> He was mixing a little imperative (the for-each ) with the declarative, and he didn't care. It was his solution.

Alistair introduced the Identity Transform: a template that copies everything, letting you override only what you need.

He wrote a rule:

Leo Martinez was a data integrator, a title his mother still didn’t understand. "So you're a plumber for information?" she’d ask. "Kind of," he’d sigh. For five years, he had tamed CSV files, wrestled JSON APIs into submission, and dreamt in SQL. But a new contract at a sprawling healthcare logistics company threw him a curveball: everything was XML. And not just neat, friendly XML. This was deep, namespaced, legacy XML, twenty levels deep, riddled with CDATA and inconsistent capitalization.

His job was to transform this beastly <ShipmentOrder> XML into a flat, friendly <OrderRecord> CSV for an ancient warehouse database. His tool? XSLT. He had a weekend to learn it.

<xsl:apply-templates select="ShipmentDetails/Package/Item"/> Nothing. The CSV was empty. He checked his XPath. It was perfect. He checked his spelling. Perfect. He replayed Alistair’s lecture. The answer was maddeningly simple: context . He was in the wrong context. The current node was still at the root. He needed ./ShipmentDetails...

Sunday, 9:00 PM. Leo ran his transformation. Saxon-HE (the XSLT processor Alistair had recommended) hummed. The output file appeared: output.csv . He opened it.

udemy xslt