Reputation: 67
I'm trying to bring some data from an XML file to another that an XSL file will create. However, I'm stuck on a part of my XSL.
XML SOURCE
<?xml version="1.0" encoding="utf-8"?>
<newsMessage xmlns="http://iptc.org/std/nar/2006-10-01/">
<itemSet>
<packageItem guid="BLABLA" version="3" standard="NewsML-G2" standardversion="2.7" conformance="power">
<contentMeta>
<altId type="TEST:ID">TEST_ID</altId>
</contentMeta>
</packageItem>
</itemSet>
</newsMessage>
XSLT:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/">
<xsl:element name="asset">
<xsl:value-of select="newsMessage/itemSet/packageItem/contentMeta/altId[@name='TEST:ID']"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
XML TARGET:
<?xml version="1.0" encoding="UTF-8"?>
<asset/>
I would like to get:
<?xml version="1.0" encoding="UTF-8"?>
<asset>TEST_ID<asset/>
I'm sure I'm missing something.. any help is appreciated.
Edit, here's the correct XSL:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://iptc.org/std/nar/2006-10-01/">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/">
<xsl:element name="asset">
<xsl:value-of select="newsMessage/itemSet/packageItem/contentMeta/altId[@type='TEST:ID']"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1
Views: 194
Reputation: 117073
You are missing two things, actually:
You are using the predicate [@name='TEST:ID']
- but the attribute's name is type
;
Your source XML is in a namespace; you need to declare the same namespace as xpath-default-namespace
in your xsl:stylesheet
element's start-tag.
Upvotes: 3