Jump to content

POM.XML dependency modification


midinges

Recommended Posts

I'm working on a translation of POM files. I have a POM file that has the following as the project stanza.<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">With the namespace information on the project statement my xsl does nothing. If I remove all the information from project and it looks like this <project> my xsl works as expected. What do I need to do to allow the template in the xsl to process this POM file?

Link to comment
Share on other sites

Try to use a universal selector in the root. That is, instead of

<xsl:template match="/project">

try using

<xsl:template match="/*">

If that doesn't work, try this:

<xsl:template match="/{http://maven.apache.org/POM/4.0.0}project">

Link to comment
Share on other sites

doing a lttle google research, i found this:

Subject: RE: how to define a namespace-prefix for null-namespaceFrom: "Michael Kay" <mike@xxxxxxxxxxxx>Date: Wed, 23 Mar 2005 18:23:42 -0000 In XSLT 2.0 you can definedefault-xpath-namespace="some.uri"which means that an unprefixed name in a path expression refers to names inthe some.uri namespace.However, it is not possible to bind an explicit namespace prefix to the"null namespace" (the set of names that are in no namespace). These can onlybe referenced using an unprefixed name. A nuisance, but that's the way itis.Michael Kayhttp://www.saxonica.com/
also
From: Dimitre Novatchev - view profile Date: Tues, Nov 14 2000 12:00 am Email: "Dimitre Novatchev" <dimit...@crosswinds.net> Groups: microsoft.public.xml.msxml-webrelease Not yet ratedRating: show options Reply | Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse | Find messages by this author Yes, and this has become a FAQ. A stylesheet will not be able to access named nodes through XPath expressions in case the xnl source document has redefined the default xml namespace -- even when the same redefinition of the default namespace has een specified on the stylesheet. Solution? Remove the default namespace redefinition and use a ***named*** namespace instead. Cheers, Dimitre Novatchev.
Link to comment
Share on other sites

Maybe a small example will help. Here is the xsl code stripped down.

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="xml" indent="yes"/>  <xsl:variable name="woodstoxct" select="count(//dependencies/dependency[normalize-space(groupId)='woodstox' and normalize-space(artifactId)='wstx-asl'])"/>  <xsl:template match="/ | @* | node()">	<xsl:copy>	<xsl:apply-templates select="@* | node()"/>	</xsl:copy>  </xsl:template>  <xsl:template match='dependency'>	<xsl:choose>	  <xsl:when test="./groupId='woodstox' and ./artifactId='wstx-asl'">		  <xsl:call-template name="axis2dep"/>	  </xsl:when>	  <xsl:otherwise>		<xsl:copy-of select="."/>	  </xsl:otherwise>	</xsl:choose>  </xsl:template>  <xsl:template name="axis2dep">	<xsl:comment>	 found <xsl:value-of select='$woodstoxct'/> Woodstox artifact(s)	</xsl:comment>	<xsl:copy>	  <groupId>artifact group</groupId>	  <artifactId>some artifact</artifactId>	  <version>1.0</version>	  <scope>provided</scope>	</xsl:copy>  </xsl:template></xsl:stylesheet>

When I run it against this xml it works and replaces the woodstox artifact

<?xml version="1.0" encoding="UTF-8"?><project>	<dependencies>		<dependency>			<groupId>woodstox</groupId>			<artifactId>wstx-asl</artifactId>		</dependency>	</dependencies></project>

If <project> is changed to have a name space as follows, it does not replace the woodstox artifact.

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">   <dependencies>		<dependency>			<groupId>woodstox</groupId>			<artifactId>wstx-asl</artifactId>		</dependency>	</dependencies></project>

Link to comment
Share on other sites

Try to add this template:

<xsl:template match="/{http://maven.apache.org/POM/4.0.0}project"><xsl:apply-templates/></xsl:template>

Link to comment
Share on other sites

Try this:

<xsl:template match="/*[local-name()='project']"><xsl:apply-templates/></xsl:template>

If that doesn't work... I don't know. Read this whole page. I've got those two tips from there.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...